1
votes

I have a DataGrid in WPF. I have binded SelectedItem property. I have Remove button which removes selected row. However when I click to other place (i.e. TextBox) and DataGrid has lost a focus, SelectedItem does not change. I can Remove the row, that was selected "earlier".

Is it default behaviour you would expected? Can it be easily fixed?

edit (code as requested):

<DataGrid SelectedItem="{Binding SelectedPort}" (...) >

<Button Command="{Binding RemovePortCommand}" >Remove Port</Button>

public ICommand RemovePortCommand
{
    get
    {
        return _removePortCommand ?? (_removePortCommand = new RelayCommand(param => OnRemovePortCommand(), param => SelectedPort != null));
    }
}
1
Post the delete and the binding.paparazzo

1 Answers

2
votes

That's Good man....

just use your Binding property to set

grid.SelectedItem =null;

OR

grid.selectedindex = -1

Or both, after delete