Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datagridview virtual mode, update RowCount causes CellValueNeeded to fire for all rows

I'm trying to implement datagridview's virtual mode but when i set RowCount to some number (to show the scrollbar) the grid wants to have all rows at once, not only the displayed.

DataGridView grid = new ...;

grid.VirtualMode = true;
grid.CellValueNeeded += OnCellValueNeeded;
grid.RowCount = dataprovider.GetFullCount();

How can i tell the grid to only request the rows displayed?

like image 502
Firo Avatar asked Dec 06 '11 17:12

Firo


2 Answers

This is just a guess, but do you have the AutoSizeRowsMode or AutoSizeColumnsMode values set to AllCells or are any of the columns set to that either? Try setting the resize mode to None or just DisplayedCells and see if there is still a problem.

like image 149
Kleinux Avatar answered Sep 23 '22 10:09

Kleinux


Not sure if this is the same problem as I was having, but I did get very poor performance when regularly drastically changing the RowCount on a VirtualMode DataGridView.

What I noticed was that the scroll bar was changing "slowly"; i.e. it looked like it was individually removing my virtual rows (!).

Anyway, doing a grid.Rows.Clear() before each call to grid.RowCount = n drastically improved performance.

like image 32
Paul Westcott Avatar answered Sep 24 '22 10:09

Paul Westcott