The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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
ADAdministrator Syncfusion Team December 30, 2002 10:25 PM UTC
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
SGSean GreerDecember 30, 2002 10:31 PM UTC
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