Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView's virtual mode implementation is broken ???
 

DataGridView's virtual mode implementation is broken ???

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
ch_cu  Tuesday, October 30, 2007 5:30 PM

Hi ch_cu

Base on my understanding,virtual mode is used formanaging the interaction between the DataGridView control and a custom data source, it is not used for reducing the number of DataGridView's rows. If we want to display a lot of data in DataGridView, we should control the data count to display. For example, we could separate a lot of data into multiple pages (like pager technologyused in ASP.NET). The following link is an example which shows how to displau data with just-in-time technology.

http://msdn2.microsoft.com/en-us/library/ms171625(VS.80).aspx

Best Regards,

Wei Zhou

Wei Zhou - MSFT  Monday, November 05, 2007 5:10 AM

Hi ch_cu

Base on my understanding,virtual mode is used formanaging the interaction between the DataGridView control and a custom data source, it is not used for reducing the number of DataGridView's rows. If we want to display a lot of data in DataGridView, we should control the data count to display. For example, we could separate a lot of data into multiple pages (like pager technologyused in ASP.NET). The following link is an example which shows how to displau data with just-in-time technology.

http://msdn2.microsoft.com/en-us/library/ms171625(VS.80).aspx

Best Regards,

Wei Zhou

Wei Zhou - MSFT  Monday, November 05, 2007 5:10 AM

You can use google to search for other answers

Custom Search

More Threads

• Datagridview - skip a readonly column
• BindingSource with embedded array - how to?
• Programmatecillay Converts Access database to sql server 2005 database
• ComboBox.SelectedIndexChanging?
• How to create datagridview during runtime?
• I try to use BindingNavigator to get current position in the table and move it to a new form
• Incremental Search
• Storing images in access database
• Datagrid Selector Sample
• FormView, SqlDataSource, ControlParameter "Oh my!"