We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Improving performance while setting styles in grid control

Hi, I am using (non-databound) GridControl to diaplay lot of data (> 20k rows). It has some floating rows (occupying all columns) and some non-floating rows. I am using Populatevalues method to load my data. Each of my columns have different styles. I have set the column styles using grid.ColStyles[col]. In some 2K cells (scattered all over the grid), I want to set different colors, fonts, alignment etc. Right now I am using grid[row,col] style info to set the style values. It takes about 4 seconds to do this. I tried using grid.ChangeCells(). But range info takes only one cell, I can not add a list of cells. Query cellInfo would be quicker, bu I will have to manage all the column moves/hiding/showing. Is there any way to speedup the loading of styles? thanks, - Reddy

14 Replies

AD Administrator Syncfusion Team November 17, 2003 07:18 PM UTC

You can directly access the GridData object instead of using an indexer on teh 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.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)
			GridStyleInfo style = new GridStyleInfo();
			style.CellValue = r.Next(100000);
			data[i, j] = style.Store;
	this.Cursor = Cursors.Default;
	this.label1.Text = string.Format("{0} ticks", Environment.TickCount - ticks);

AD Administrator Syncfusion Team June 8, 2004 05:08 PM UTC

Does this effect the grid style already in place for each cell?

AD Administrator Syncfusion Team June 8, 2004 05:57 PM UTC

If you want to use the style that is already there, then instead of creating a new GridStyleInfo, you would get a style object based on the existing cell style.
GridStyleInfo style;

if(data[i,j] != null)
   style = new GridStyleInfo(data[i,j]);
   style = new GridStyleInfo();

style.CellValue = r.Next(100000);
data[i, j] = style.Store;

AD Administrator Syncfusion Team June 10, 2004 04:15 PM UTC

Where are the settings stored when a change is made in design mode? After applying the code snippet you supplied I was stepping through a debug session and noticed the first time through the style object is always equal to null. For example I set several columns to CellType = "Currency" but when I step through the debug it says CellType = “TextBox”? Any ideas? John

AD Administrator Syncfusion Team June 10, 2004 04:25 PM UTC

Are you using a GridControl? The code only works in a GridControl that holds its own data. Where are you checking the values for the style objects? You would have to be doing the check after QueryCellInfo has been hit for that particular cell. If you do a GridStyleInfo style1 = this.gridControl1[2,2], after executing the previous code, you should see the values you set in that code. Settings done to cell style objects at design time should be set in the design generated code. So, if you check GridStyleInfo style1 = this.gridControl1[2,2] in formload after setting some style property on cell 2,2 at design time, I think the the style should reflect the settings.

AD Administrator Syncfusion Team June 11, 2004 11:07 AM UTC

I’m using an, Essential Grid version, GridControl with Visual Basic.Net. I have included a sample with some notes in the code. Thank you, JT StyleObject_5930.zip

AD Administrator Syncfusion Team June 11, 2004 11:25 AM UTC

>> '''''''''' this line is the one that seems to be fouling me up, as "data(0,i)" is always = to nothing at this point If Not data(0, i) Is Nothing Then This is the column header row, and the column header row normally never stores anything unless you explicitly put stuff in it. It gets all its settings from the grid.BaseStyleMap("Column Header").StyleInfo. In a gridcontrol, the header cell text (A, B , C, etc) are auto generated and are not stored in any data object. The grid does not use space in the GridData object unless it absolutely has to, and that is usually when you explicitly set a particular cell style property. Now once uyou set properties on a particular cell in GridData, you should then be able to retrieve a non-null value. Does this explain what you are seeing?

AD Administrator Syncfusion Team June 11, 2004 11:37 AM UTC

No I also get the same results in “grdNBSA_ClearingCells”

AD Administrator Syncfusion Team June 11, 2004 11:40 AM UTC

Maybe I''m not asking the right question, I have made changes in design mode using the column style editor where is this information stored? Is this in the style object that I am checking?

AD Administrator Syncfusion Team June 11, 2004 12:19 PM UTC

Here is the line from the generated code that loads the design time information into the GridData object. Me.grdNBSA.Data = CType(resources.GetObject("grdNBSA.Data"), Syncfusion.Windows.Forms.Grid.GridData) I looked at your project at design time, and did not see any cell-specific style proerties set (may have missed some). The only style properties I saw set were in the RowStyles collection and in the ColStyles collection. If you set a style property, say in ColStyle(2), then you do not see this property by accessing griddata(1, 2), or griddata(2,2) or griddata(3,2). These objects are only instantiated if you set cell specific properties. If you want to retrieve the column style object for column 2, try griddata(-1, 2). The -1 row index will retrieve colstyle properties. Using -1 for the colIndex will retrieve the rowstyles from the griddata object. Using -1 for both indexes will retrieve the tablestyle from the griddata object.

AD Administrator Syncfusion Team June 15, 2004 11:34 AM UTC

Thank you for the information, we generally use the ColStyle(n) to set Grid Control properties in the designer. What is the fastest way to get data in and out of the grid? The code snippet above was a vast improvement over the indexer method I started with. This is what I have now modified using the info from your last post, is this the most efficient way to do this? I need to preserve the settings made at design time. Dim style As GridStyleInfo Dim data As GridData = grdNBSA.Data For i = 0 To 127 For l = 2 To sources + 1 If Not data(-1, l) Is Nothing Then style = New GridStyleInfo(data(-1, l)) Else style = New GridStyleInfo End If With style .CellValue = (l - 2 + i / 100) data(i + 1, l) = .Store End With Next Next Or is this better? For i = 0 To 127 For l = 2 To sources + 1 Dim style1 As GridStyleInfo = Me.grdNBSA(i+1,l) With style1 .CellValue = (l - 2 + i / 100) data(i + 1, l) = .Store End With Next Next

AD Administrator Syncfusion Team June 15, 2004 01:14 PM UTC

I think the first way is better, but you could set up some tests to make sure. One comment that would possible make things better is to switch the order of your i and l loops. In the first case, you could create a style1 object that held the column style for a particular column. Then in the inner row loop, you could create style = new GridStyleInfo(style1) that would be a copy of your column style, and then set and save the properties on style. This way you would retrieve the column style once for each column (and not retrieve it for every row).

PB Philip Bishop January 12, 2005 05:16 PM UTC

This is a question about this and the new We have some forms where we load like JT was talking to drastically speed up load times and some that we havent changed yet. Some of the forms we havent changed yet do the double for loop and load data using the indexer technique where we load the cell value during the for loop. my question is in testing some stuff with a co-worker who doesnt have yet i noticed HUGE speed up times on the indexer way of loading on my new version of the grid versus hers using Say the form took 5 to 6 seconds to come up on hers, mine using the new grid with the old styly of loading took 1 to 2. So did you guys change something to speed up performance on load time even using the indexer method to load as opposed to the way you recommended in this link?

AD Administrator Syncfusion Team January 13, 2005 12:36 PM UTC

We didn''t specifically work on this issue but we made some optimizations in the GetHashCode routines used within GridVolatileData. So your observation might be a nice side effect of that. Stefan

Live Chat Icon For mobile
Up arrow icon