This is a migrated thread and some comments may be shown as answers.

AddRange and GridView performance

5 Answers 1123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 1
Roberto asked on 03 Nov 2010, 06:11 PM

Hi all,

I am experimenting some troubles in speeding up the filling of a RadGridView. If I fill it row by row (Add method) the result is correct but slow (more than 10s for 300 rows). If I create a GridViewRowInfo array and then fill the Grid with AddRange the task is completed istantaneously, but then the result differs from the one obtained through the Add method (problems in row selection and column resize, not depending on the AllowX properties). In particular I think the my errors are in creating each GridViewRowInfo, that needs a GridViewInfo that needs a GridViewTemplate. Here the code:

GridViewTemplate template = new GridViewTemplate();
template.AllowColumnResize = true;
 
foreach (GridViewColumn col in myGrid.Columns)
  template.Columns.Add((GridViewDataColumn)col);
 
GridViewInfo info = new GridViewInfo(template);
GridViewRowInfo row = new GridViewRowInfo(info);
row.AllowResize = true;
 
// oRow contains the values for the cells
for (int i = 0; i < oRow.Length; i++)
  row.Cells[i].Value = oRow[i]; 
 
row.Tag = epropSample;

Hope someone could help!
Thanks in advance!
Roberto

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 03 Nov 2010, 11:04 PM
Hello Roberto,

First i would like to ask you why don't you use a data source for the grid? That way is the fastest, after that is the AddRange....

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Roberto
Top achievements
Rank 1
answered on 04 Nov 2010, 09:09 AM
Hi Emanuel,

I didn't bind the Grid to a data source mainly because the data I want to store in the grid are not in a database, and I didn't want to manually create a DataSet. I don't know if this is a good answer, but I am open to any suggestion. I fall to the AddRange method because the same performance issue between Add and AddRange was known about .net framework DataGridView.

Best Regards
Roberto
0
Richard Slade
Top achievements
Rank 2
answered on 04 Nov 2010, 10:06 AM
Hi, 

I agree with Emanuel. Even if you are not storing the data in a database, you can still create a datasource (doesn't have to be a dataset) to bind to the grid. It will certainly be the fastest. 

Richard
0
Phi
Top achievements
Rank 1
answered on 04 Nov 2010, 02:11 PM
Yup! That is what I have to do after finding out that using Add is extremely slow for large amount of data! I use BindingList<T> and it is really really fast!
0
Roberto
Top achievements
Rank 1
answered on 04 Nov 2010, 03:26 PM
Ok, thanks you all!

Eventually I used a DataTable as DataSource for the Grid.

Thanks again!
Roberto
Tags
GridView
Asked by
Roberto
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Roberto
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Phi
Top achievements
Rank 1
Share this question
or