Romain

Romain

  • NA
  • 76
  • 39.3k

How to disable cell and apply the changes in a datagrid WPF

Jun 6 2014 5:38 AM
Good morning,
 
 I am working on an application which uses a datagrid. The datagrid contains 5 columns and the content of each cells  depends of an ObservableCollection.
The  3rd column contains a combo box : when you edit a cell of the column, a combo box appears and you can select a value between four.
 
What I wanted to do is when I select the 2nd value of the combo box whis is called "Item2", the cell at the 4th column at the same row is no longer enable.
Actually I did the thing below :

 private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
      string textComboBoxItem = e.AddedItems[0].ToString();
      var selectedRow = this.dataGrid.GetSelectedRow();

  
      if (textComboBoxItem!= "Item2")
      {
            this.dataGrid.GetCell(selectedRow, 4).Content = "";
            this.dataGrid.GetCell(selectedRow, 4).IsEnabled = false;
      }
}

 
It works but when I "quit" the cell with combo box, the change made by the action "isEnabled=false" is not applied. How can I male the change active ?
 
Note : The functions  GetSelectedRow(), GetCell are made for movin inside the datagrid.
 
Thanks in advance for any advice.