Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Unbound 600 x 20 DataGridView displaying 50 cols x 13 rows, horizontal scrolling is slow and jerky
 

Unbound 600 x 20 DataGridView displaying 50 cols x 13 rows, horizontal scrolling is slow and jerky

Hi,

I have an unboudn DataGridView control which I populate with hundreds of Columns (usually aorund 600) and anywhere from 12 to 20 rows. Each cell is a DataGrivTextBoxCell whose Value is set to a char. When the user scrolls horizontally, the grid scrolls jerkily, and takes several seconds to draw itself before jerk-advancing the sroll thumb (which itself jumps along the scrollbar).

I'd like the scrolling experience to be smooth.

I've tried setting properties off whereever possible to minimize overhead the DataGridView might have. For example:

Code Block

dg.AutoSize = false;

dg.AllowUserToAddRows = false;

dg.AllowUserToDeleteRows = false;

dg.AllowUserToOrderColumns = false;

dg.AllowUserToResizeColumns = false;

dg.AllowUserToResizeRows = false;

dg.ReadOnly = true;

dg.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;

dg.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;

dg.EditMode = DataGridViewEditMode.EditProgrammatically;

dg.ColumnHeadersVisible = false; //set true afteradding columns; speed optimization

dg.Refresh();

Any ideas?
SpockMonster  Wednesday, November 14, 2007 10:07 PM

Several ... though you may not like any of them!<G>

1) Realistically speaking, a normal person cannot glean 600 columns. I would provide some type of filter that would show different sets of columns. Using customer as an example: contact info, sales person info, credit history, shipping info, etc.

2) Change the rows to columns and the columns to rows. Rows seem to scroll more smoothly than columns. (At least in my little examples.)

3) Where is the codethat you have above? (what event?) That Refresh will cause the grid to get repainted ... and I don't think it is needed?

Hope this helps.

DeborahK  Wednesday, November 14, 2007 10:14 PM

1. System requirements mandate this layout. It is presenting scientific data, there is no summary view that would be suitable. In this case, the humans are specially trained to use data in this format. It is the normal format for presentation of this data.

2. The choice of row and column major could not be reversed without causing user orientation.

3. There is no code above, what I demo'd was just initializg the DataGridView. Likewise, the Refresh is not within a loop and is called only once in the above.

Notice that Excel is able to fluidly scroll the view of a large spreadsheet. Why should not DataGridView be fluid? I would prefer to use a control from theCore Library, and I sure do not want to migrate my UI to VSTO while hostig Excel. Ugh.

Here is a little sample that demo's the issue. Fill the grid, and then try scrolling it. You'll need to paint a rather large DataGridView and name it "dg", and a button to load the gridnamed "loadGrid".

Code Block

public partial class BigGrid : Form

{

public BigGrid()

{

InitializeComponent();

}

private DataGridViewColumn getCol()

{

DataGridViewColumn dgcol = new DataGridViewColumn();

dgcol.FillWeight = 1;

DataGridViewCell dgcell = new DataGridViewTextBoxCell();

dgcol.CellTemplate = dgcell;

dgcol.Width = 15;

return dgcol;

}

private void loadGrid_Click(object sender, EventArgs e)

{

dg.ClearSelection();

dg.ReadOnly = true;

dg.AllowUserToAddRows = false;

dg.AllowUserToDeleteRows = false;

dg.AllowUserToOrderColumns = false;

dg.AllowUserToResizeColumns = false;

dg.AllowUserToResizeRows = false;

DataGridViewCellStyle cs = new DataGridViewCellStyle();

for (int y = 0; y < 700; y++)

{

DataGridViewColumn dgcol = getCol();

dg.Columns.Add(dgcol);

}

for (int x = 0; x < 20; x++)

{

int r = dg.Rows.Add();

DataGridViewRow dgr = dg.Rows[r];

for (int y = 0; y < 700; y++)

{

dgr.Cells[y].Value = "X";

}

}

}

}

Is there some way I could build the grid more to more efficiently scroll?

- Is there a more efficient cell to use than a DataGridViewTextboxCell? Like a DataGridViewLabelCell (which there isn't)?

- The Grid is set ReadOnly=true, all the Allows are set false. Is there any other optimization that might cut out a bunch of overhead that is needed for edittable grids (which a read-only would therefore not need)?

- Is the DataGrid a fast scroller in this situation?

SpockMonster  Thursday, November 15, 2007 4:29 PM

You can use google to search for other answers

Custom Search

More Threads

• Make text bold on specific datagrid row?
• Dataset being modified??
• Temp table and Add row to this table
• Open form with button
• How to create custom Format for DataGridView?
• Connect a combobox to SQL server
• Coloring Datagrid rows based on value inside of dataset
• "multiple rows" If select all checked true ~ insert old data with updated dates appended to database for logging Mgr decision
• Issue DataGridview and Hiding columns.
• How to disable Page in Tab control in c# 2.0