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

Performance of adding GridBoundColumns

I'm using a GridDataBoundGrid to display the results of a user-issued query. I loop through the result set and add a GridBoundColumn for each column, set the CellType to Static and in the case of datetime columns, I set the format. When a different query is issued, a new DataSet is created to hold the results, but the same grid is used for presentation. This is when I run into problems. The first time I generate the GridBoundColumns the process takes about 1 second for 24 columns. On subsequent iterations, the time to generate 24 columns increases to 10 or more seconds. I'm using the code below: m_dgResultGrid.SuspendLayout(); m_dgResultGrid.Binder.SuspendBinding(); m_dgResultGrid.Model.SuspendChangeEvents(); m_dgResultGrid.DataSource = null; m_dgResultGrid.GridBoundColumns.Clear(); DateTime dtBegin = DateTime.Now; foreach(DataColumn dc in dataSet.Tables[0].Columns) { GridBoundColumn gbc = new GridBoundColumn(); gbc.MappingName = dc.ColumnName; gbc.HeaderText = dc.ColumnName; if(dc.DataType == typeof(DateTime)) { gbc.StyleInfo.Format = "g"; } gbc.StyleInfo.CellType = "Static"; m_dgResultGrid.GridBoundColumns.Add(gbc); } TimeSpan ts = DateTime.Now - dtBegin; Debug.WriteLine(string.Format("Time to generate columns: {0}", ts.TotalMilliseconds)); // set the datasource m_dgResultGrid.Binder.ResumeBinding(); m_dgResultGrid.ResumeLayout(); m_dgResultGrid.Model.ResumeChangeEvents(); Any thoughts on why I'm seeing this behavior? Sean

2 Replies

AD Administrator Syncfusion Team December 30, 2002 05:25 PM

Sean, try creating a GridBoundColumn[] array and then call GridBoundColumnsCollection.AddRange with that array. That way the grid will have not to reinitialize all columns after each Add call. Stefan


SG Sean Greer December 30, 2002 05:31 PM

Stefan, Thanks for the suggestion - it resolved the issue. The time to update the columns is now closer to .3 seconds, which is quite acceptable. Sean

Loader.
Live Chat Icon For mobile
Up arrow icon