Posted 6 February 2018, 1:45 am EST
Today we wanted to improve our performance on our Datagrid where we select Datagrid Cells depending on some Settings the User can change.
Up to today we just used Selection.Add() and Selection.Remove()
As i said we wanted to speed this up since the Datagrid can have 40.000 lines and we added a call Selection.BeginUpdate() before we Add several Columns and added the Selection.EndUpdate() after we added all Columns and Removed all unwanted Rows.
So our way up to now was:
- Add Columns 1-X
- Remove Rows 1-X
now we have:
- BeginUpdate()
- Add Columns 1-X
- Remove Rows 1-X
- EndUpdate()
While testing the new implementation we had to find out that the system is not working as before.
The reason: When using BeginUpdate and EndUpdate the Remove from the Selection is simple not done.
In our opinion this is fundamentally wrong. The result using BeginUpdate/EndUpdate and doing the same without BeginUpdate/EndUpdate should always be the same. after the whole block is processed.
Demo Code (DataGrid with 10 Rows, 2 Columns):
DemoGrid.Selection.Clear();
DemoGrid.Selection.BeginUpdate();
DemoGrid.Selection.Add(DemoGrid.Columns[0], DemoGrid.Columns[0]);
DemoGrid.Selection.Remove(DemoGrid.Rows[0], DemoGrid.Rows[0]);
DemoGrid.Selection.EndUpdate();
Result in this case is that every Cell in First Column is selected.
DemoGrid.Selection.Clear();
DemoGrid.Selection.Add(DemoGrid.Columns[0], DemoGrid.Columns[0]);
DemoGrid.Selection.Remove(DemoGrid.Rows[0], DemoGrid.Rows[0]);
Result in this case is that all Cells in the First Column are selected exceptthe Cell from First Row/FirstColumn
So there are different results when using BeginUpdate and EndUpdate.
greetings