0

I keep getting an exception (see below) when I retrieve a list of rows from a Virtual Mode datagrid, this only happens when I have more rows than I can display on screen and it doesn't happen every time. Is there anything I'm missing with regards to virtual mode?

Update> The image below shows the problem, the index is now outside the list range. The reason for this is say I have 10 items and I hide 5 as they are not needed and I want to run some code on the 5 that are visible, there are now 5 items but the index of some maybe between 5-9, how can I re-index? When I have run some code on the visible 5 I then show the hidden 5 so I don't want to disgard these, I'd need to reindex again when they are all visible. Many thanks.

alt text

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
  • I've added a 3rd pic showing the value as null for the failed row, this is either true or false for other rows. –  Jul 27 '09 at 14:42
  • I've removed the older pics as the new pic clearly shows the problem, I need to re-index (I think), how would I do this? Thanks –  Jul 27 '09 at 14:57

4 Answers4

0

I've only used virtual mode with DataGridView, but in virtual mode you are supposed to store the data yourself and provide it when the datagrid needs to for rendering. I suppose the datagrid is only creating the minimum number of items that is needed to fill the view and then reuse them for performance reasons.

Daniel
  • 1,417
  • 2
  • 12
  • 20
0

This looks sort of like a threading problem to me. Are you using a BackgroundWorker or something similar to populate the _items variable? It looks like the number of things in _items is changing while you are looping over it.

Perhaps you could try surround any and all code dealing with _items with this:

lock (_items) 
{
    // your code
}

Alternatively, break out of these functions and return null if your population/alteration code is still running (use some kind of boolean sentinel variable perhaps).

Jon Grant
  • 11,369
  • 2
  • 37
  • 58
0

How have you set up your databinding.

Would it be possible for you to work against the underlying dataset instead of going via the datagrid.

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • Hi Shiraz, Its a long story but I ideally need to use the data that I have already in the datagrid. –  Jul 27 '09 at 14:41
0

Just be aware of DataGridView's virtual mode limitations. Despite of its supposed low-memory consumption feature (only visible rows gets loaded from database); each row has their own instance (to prove, try to resize each of DataGridView rows, rows' sizes can be set independently of each other, thus each row's information(e.g. RowHeight) need be saved in their own memory)

When you set the RowCount, it will instantiate n number of rows from what you specified in RowCount. Thus defeating one of the original purposes of DataGridView's virtual mode, low-memory consumption. Too much memory consumption could slow down your datagrid display

See my article here http://www.codeproject.com/KB/grid/DataGridView_Billion_Rows.aspx, and the other article http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/243a81e7-909b-4c8e-9d28-6114248cf66e

Michael Buen
  • 38,643
  • 9
  • 94
  • 118