Reputation: 22200
I have a DataGridView control on my windows application form. This DataGridView is populated on the basis of a plain text file (specified by user at run time). Hence the number of columns and rows are calculated dynamically. Now the every thing works fine as expected the only issue is that my DataGridView took a lot of time to load data, is there any way to optimize the performance of DataGridView?
Hint: Normally the datagridview contians 1024 columns and almos 100 rows.
Following is the code for populating my DataGridView
dataGridView1.ColumnCount = nColumnCount;
for (int i = 0; i < CurrPageLines.Length; i++)
{
string sCurrLinecontents = CurrPageLines[i];
int n = dataGridView1.Rows.Add();
for (int j = 0; j < /*nColumnCount*/sCurrLinecontents.Length; j++)
{
dataGridView1.Rows[n].Cells[j].Value = sCurrLinecontents[j];
}
}
Upvotes: 3
Views: 10628
Reputation: 19050
There is an article on MSDN on how use the virtual mode of the datagridview. It even comes with a nice walkthrough example. Although it seems to be more targeted towards lots of rows instead of lots of columns it might still be useful.
Update: If you are just experiencing delays when loading data you might be able to improve things by creating a DataTable
or a BindingList
from your textfile and then bind that to the view.
Upvotes: 6