Grid performance when setting values

Hi there, I have a simple application that host the grid control, with about 1000 rows x 20 columns. I am looping through each cell and set its value. I try do do it in two different ways, 1) m_gird[nRow, nCol].Text = "abc"; 2) m_grid[nRow, nCol].CellValue = "abc"; it looks like (2) is faster than (1). However, I only interested in setting the cell''s value. Why is OnStyleChanged needed to be sent out? I am using Rational Quantify to do some profiling, and I see alot of time is spent in the GridStyleInfo.OnStyleChanged(..) when I am only setting the cell value. Is the function OnStyleChanged need to be executed when I only changing the text? Anyway, is there a more efficient way to change the cell text for the grid control? I am getting a couple seconds of delay when I initialize the grid in the constructor of my application. thanks, -patrick

2 Replies

AD Administrator Syncfusion Team April 21, 2005 10:20 PM UTC

You can directly access the GridData object instead of using an indexer on the grid. This will avoid events and probably be a factor of 5 - 10 times faster.
private void button1_Click(object sender, System.EventArgs e)
{
	int nRows = 8500;
	int nCols = 25;
	Random r = new Random();
	this.Cursor = Cursors.WaitCursor;
	int ticks = Environment.TickCount;
	this.gridControl1.BeginUpdate();
	this.gridControl1.RowCount = nRows;
	this.gridControl1.ColCount = nCols;
	GridData data = this.gridControl1.Data;
	for(int i = 1; i <= nRows; ++i)
	{
		for(int j = 1; j <= nCols; ++j)
		{
			// instead of      this.gridControl1[i,j].CellValue = ????
			//use this code
			GridStyleInfo style = new GridStyleInfo();
			style.CellValue = r.Next(100000);
			data[i, j] = style.Store;
		}
	}
	this.gridControl1.EndUpdate();
	this.gridControl1.Refresh();
	this.Cursor = Cursors.Default;
	this.label1.Text = string.Format("{0} ticks", Environment.TickCount - ticks);
}


AD Administrator Syncfusion Team April 22, 2005 06:29 PM UTC

Thanks, it helps a lot. -patrick

Loader.
Up arrow icon