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.
Unfortunately, activation email could not send to your email. Please try again.

Improving performance while setting styles in grid control

Thread ID:

Created:

Updated:

Platform:

Replies:

8704 Nov 17,2003 12:48 PM Jan 13,2005 07:36 AM Windows Forms 14
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On November 17, 2003 12:48 PM

Hi, I am using 1.6.1.8 (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

Administrator [Syncfusion]
Replied On November 17, 2003 02:18 PM

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.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)
		{
			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);
}

Administrator [Syncfusion]
Replied On June 8, 2004 01:08 PM

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

Administrator [Syncfusion]
Replied On June 8, 2004 01:57 PM

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]);
else
   style = new GridStyleInfo();

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

Administrator [Syncfusion]
Replied On June 10, 2004 12:15 PM

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

Administrator [Syncfusion]
Replied On June 10, 2004 12:25 PM

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.

Administrator [Syncfusion]
Replied On June 11, 2004 07:07 AM

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

Administrator [Syncfusion]
Replied On June 11, 2004 07:25 AM

>> '''''''''' 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?

Administrator [Syncfusion]
Replied On June 11, 2004 07:37 AM

No I also get the same results in “grdNBSA_ClearingCells”

Administrator [Syncfusion]
Replied On June 11, 2004 07:40 AM

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?

Administrator [Syncfusion]
Replied On June 11, 2004 08:19 AM

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.

Administrator [Syncfusion]
Replied On June 15, 2004 07:34 AM

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

Administrator [Syncfusion]
Replied On June 15, 2004 09:14 AM

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).

Philip Bishop
Replied On January 12, 2005 12:16 PM

This is a question about this and the new 3.0.1.0. 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 3.0.1.0 yet i noticed HUGE speed up times on the indexer way of loading on my new version of the grid versus hers using 2.0.5.0. 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?

Administrator [Syncfusion]
Replied On January 13, 2005 07:36 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;