I've been using DGV's VirtualMode for a few weeks just to realized that
MS's implementation seems really buggy. Could you help me maybe on that
topic?
If I'm not wrong, I'm supposed to set DGV.RowCount property to the
number of rows from the underlying DB. The problem is that setting
RowCount to X will internally create/resize two collections (the
RowArrayList and the List<DataGridViewElementStates>) to that size. Each
item in the collections are not that big, but if my underlying DB's
table has hundreds of thousands of rows, then the DGV is
going to take 10-15 MB of RAM.
You can actually see this in details by using Reflector. Look to the
RowCount setter: it calls DGV.Rows.Add(int), which itself calls
DataGridViewRowCollection.AddCopiesPrivate(rowTemplateClone, state, count).
As a conclusion, whereas we're in VirtualMode, the DGV internally
creates some 'objects' whose size is proportional to the number of rows
theoretically present in the virtual grid, hence defeating the whole
purpose of the VirtualMode.
Am I missing something? Or did MS engineers got it wrong?
Thanks for your help,
Chris