how to stop selected columns refresh in wpf datagrid
I am using datatable to bind to wpf datagrid and refreshing items of datagrid by using background worker , in my datagrid i am using a checkbox for selecting items. Because of the background worker , when i do checkbox checked, it is unchecking as background worker is running, if i comment the datagrid binding logic in background worker , checkbox is getting checked. Can any one help how to do checkbox get selected even when datagrid items are getting refreshed. i am creating checkbox using "DataGridCheckBoxColumn ". Thanks for the help in advance
Microsoft Development.NET Programming
Last Comment
pkoivula
8/22/2022 - Mon
dj_alik
You are working with datatable try to bind the 'checked' flag field to some column(Boolean) in datatable and when your refresh the datasource in background worker you can do merging between previous datatable and new one (datatable.Merge())
that will save state of your checked flags.
in addition is recommended to have primary keys in datatable.
dj_alik
better: please do not add the check field column to new datatable... on refresh/merge.
pkoivula
ASKER
We are following the same pattern datatable.Merge() , but it didn't helped me in getting the problem solved. I am filling datatable from dataset , and using merge on it. Now i am binding the datatable to datagrid.
for binding data i wrote a method with this functionality
getDataForConsole.Tables[tableName].Merge(objPlanningConsoleUIController.GetCachedDataSet()); //filling data from dataset
if (getDataForConsole.Tables[tableName].Rows.Count > 0)
{
if (_resetBinding ||
dtGrdTemp.ItemsSource == null ||
dtGrdTemp.Items.Count == 0)
{
dtGrdTemp.ItemsSource = getDataForConsole.Tables[tableName].DefaultView;
_resetBinding = false;
}
}
I called this functionality method in background worker in RunWorkerCompleted event.
please tell how to stop refreshing particular datagrid row columns.
dj_alik
ok as I said you need may be to merge with table without field flag...
may be it's complex to describe.
First Load of Datatable with primary keys and 'Selected Flag Field'\Column
secondary load and next: Merges with Table without 'Selected Flag Field'\Column' in Schema.
you can add dynamically the check column in first load: DataTable.Columns.Add("Selected",typeof(Boolean)) and please bind it to checkbox column.
that will save state of your checked flags.
in addition is recommended to have primary keys in datatable.