Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Extremely Slow Population of a DataGridView
 

Extremely Slow Population of a DataGridView

I'm using a DataTable-bound DataGridView that has ~20-30 columns of mostly Strings in a Windows Forms Application made in Visual C# 2008 Express. When I load ~40 rows into the table, the application appears to freeze, but 5-10 minutes later, it becomes responsive again (except for the vertical scroll bar, which has un-refreshed garbage in its place). Why is this happening? Thanks in advance.

Vivek
Viv1357  Tuesday, April 22, 2008 8:43 PM
I think I figured out why this is happening -- I wasn't making a thread-safe call while populating the DataGridView control. After I used the delegate method below, the problem disappeared:

Code Snippet

delegate void AddToDataTableCallback(MyRowData pInfo);
private void AddToDataTable(MyRowData pInfo)
{
if (dataGridView1.InvokeRequired)
{
AddToDataTableCallback a = new AddToDataTableCallback(AddToDataTable);
this.Invoke(a, new object[] { pInfo });
}
else
DataRow row = DataTable1.Rows.Add(pInfo.ToArrayList().ToArray());
}


Viv1357  Wednesday, April 23, 2008 8:17 PM
I think I figured out why this is happening -- I wasn't making a thread-safe call while populating the DataGridView control. After I used the delegate method below, the problem disappeared:

Code Snippet

delegate void AddToDataTableCallback(MyRowData pInfo);
private void AddToDataTable(MyRowData pInfo)
{
if (dataGridView1.InvokeRequired)
{
AddToDataTableCallback a = new AddToDataTableCallback(AddToDataTable);
this.Invoke(a, new object[] { pInfo });
}
else
DataRow row = DataTable1.Rows.Add(pInfo.ToArrayList().ToArray());
}


Viv1357  Wednesday, April 23, 2008 8:17 PM

You can use google to search for other answers

Custom Search

More Threads

• Databound feature for user controls in windows applications in vb.net
• control.invoke
• Display null data as blank cell in datagrid
• datagridview vertical scroll bar
• ListBox in Access
• How do I retreive the contents of a field from current record in BindingSource?
• Textbox databinding in a data Form (Autocalculated fields )
• Datagrid does not allow delete row when "EditOnEnter"
• Newbie question: Common Binding Sources for several Forms?
• data grid changing sizes of columns