J
John Richardson
I've been bothered for some time about my DataGrid not populating my rows
very quickly. I have about 10K rows loading into the grid.
I create a datatable dt with 2 columns, an ID and a display. The ID is a
member of the keys array.
I then create a DataView dv over the table, and sort it by Display and ID
column (in case of duplicate Display).
I then set my DataGrid.DataSource = dv;
I then load the datatable with my rows, and this is what I find is very
interesting, and any explanation would be very appreciated:
When the form loads, I call a method LoadList(). In this method, I test to
see if the DataGrid.DataSource is null, and then I set it if TRUE.
If the DataGrid.DataSource has already been set, then I leave it alone.
I retrieve the datatable from the source, and load the table.
I can also call LoadList from a user request to refresh the grid.
At the Form.Load the rows are added very quickly to my datatable.
At the user request, the rows are added at a factor of speed over 1000x
slower, and the speed decreases as n, the number of rows, increases.
I then removed my test to see if the DataGrid.DataSource is null, and now I
RESET the datasource each time the LoadList() method is called. So, I
recreate my DataTable, Styles each time. And, my speed is lightning fast
again. Apart from resetting the datasource, all the code is the same.
I have a feeling that it could be related to either sorting, or some kind of
event handling firing for each row in the grid each time the grid is added
to. It has to be something related to the size of n... but I don't know
what it could be. Anyone with any experience with this?
very quickly. I have about 10K rows loading into the grid.
I create a datatable dt with 2 columns, an ID and a display. The ID is a
member of the keys array.
I then create a DataView dv over the table, and sort it by Display and ID
column (in case of duplicate Display).
I then set my DataGrid.DataSource = dv;
I then load the datatable with my rows, and this is what I find is very
interesting, and any explanation would be very appreciated:
When the form loads, I call a method LoadList(). In this method, I test to
see if the DataGrid.DataSource is null, and then I set it if TRUE.
If the DataGrid.DataSource has already been set, then I leave it alone.
I retrieve the datatable from the source, and load the table.
I can also call LoadList from a user request to refresh the grid.
At the Form.Load the rows are added very quickly to my datatable.
At the user request, the rows are added at a factor of speed over 1000x
slower, and the speed decreases as n, the number of rows, increases.
I then removed my test to see if the DataGrid.DataSource is null, and now I
RESET the datasource each time the LoadList() method is called. So, I
recreate my DataTable, Styles each time. And, my speed is lightning fast
again. Apart from resetting the datasource, all the code is the same.
I have a feeling that it could be related to either sorting, or some kind of
event handling firing for each row in the grid each time the grid is added
to. It has to be something related to the size of n... but I don't know
what it could be. Anyone with any experience with this?