I have a DataGrid control binded to DataTable using the following:
dataGrid1.ItemsSource = dataTable1.DefaultView;
Now I would want to items in my DataGrid changes corresponding to user selection in a ComboBox. I.e. I will need to bind to the dataTable selectively? The following code works but I felt it’s being overkill:
dataView1 = new DataView(
dataTable1,
"Combox_ID = " + comboBoxId,
"ID ASC",
DataViewRowState.CurrentRows);c
DataTable dataView1DataTable = dataView1.ToTable();
dataGrid1.ItemsSource = dataDvDt.DefaultView;
Is there a simplier way to do this, something like the following but works?
/* below code doesn't work */
dataGrid1.ItemsSource = dataTable1.Select("ComboBox1_ID = 0").DefaultView;
Just bind to the
DataViewitself, like you’re technically already doing.Unless you want to protect the original data from modification there’s no need to create a new table copy.