2
votes

I need to display an unknown length sequence of dictionaries with unknown keys efficiently in a data grid. This sequence is the result of a potentially slow LINQ query that could contain any number of results.

At first I thought that VirtualMode on DataGridView was what I was looking for but it appears that the number of rows and columns must be known upfront. I tried adding a single row and column then adding more as needed from the CellValueNeeded event but this doesn't work.

Is this even possible with VirtualMode? Or do I need to estimate how many rows are visible on the screen and manually build up the rows/columns? And if so, how do I ensure that a vertical scrollbar is present and react appropriately when a user uses it?

1

1 Answers

0
votes

You can simply have a IBindingList collection that will notify the grid to update as the rows are added. So you query using LINQ and populate this collection which can be any 'N' number. During initial load, may be set some fixed rows to the collection as the initial record set, say 1000, and then keep adding rows to the collection as you iterate your LINQ query.

-Fahad