Using VirtualMode in DataGridView when row / column count is unknown
I need to display the unknown length of a sequence of dictionaries with unknown keys efficiently in a data grid. This sequence is the result of a potentially slow LINQ query that can contain any number of results.
At first I thought that the VirtualMode on the DataGridView is what I was looking for, but it seems like the number of rows and columns should be known in advance. I tried adding one row and column and then adding more as needed from CellValueNeeded , but that doesn't work.
Is this possible with VirtualMode? Or do I need to estimate how many rows are visible on the screen and manually create rows / columns? And if so, how can I provide a vertical scrollbar and react appropriately when the user uses it?
a source to share
You can simply have an IBindingList collection that will notify the grid to update as rows are added. So you query LINQ and populate this collection, which can be any number "N". During bootstrapping, you can set a few fixed rows in the collection as an initial recordset, for example 1000, and then keep adding rows to the collection as the LINQ query is repeated.
-Fahad
a source to share