0
votes

I have a DataGrid, whose ItemsSource binding to an ObservableCollection. And:

  • The 1st column binding to Name property;
  • The 2nd column binding to Age property;

Example Image

Now I want to add the 3rd column, using DataGridComboBoxColumn control. And it's content shall be all the Names of column 1. When adding or removing a row, the content of DataGridComboBoxColumn shall add or remove a Name correspondingly.

The only way I thought out is very silly: Just create a new ObservableCollection called NameList. And everytime adding or removing a row to DataGrid, add or remove a name to the NameList at the same time.

Is there any better way?

1

1 Answers

0
votes

Add an new property that has only a getter and bind it to the Visibility property of the first column.

Do not forget to execute OnPropertyChanged for the added property when the value of the third column get modified.