strings. I tried BeginLoad() but it had no effect.
Post by Jeffrey Tan[MSFT]Hi Jeffery,
Based on my understanding, you want to improve the performance of
databinding in DataGrid while adding multiple new rows.
When we are adding new datarows into DataTable, the databinding code will
force the new added row to be displayed in the DataGrid control. Since the
databinding code will parse and display for each one row adding, so the
entire performance is slow if we are adding tens of thousands of rows. So
the normal idea is suspending the databinding and adding all the new rows,
finally, we may resume the databinding process again. This will allow the
databinding code to touch the DataGrid control in one push, which increases
performance.
If you are using .Net1.1, there is no hook to suspend the databinding, so
the only way I can think of is cut off the datasource, adding new rows and
DataTable dt;
private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item" + i.ToString();
dt.Rows.Add(dr);
}
this.dataGrid1.DataSource = dt;
}
private void button2_Click(object sender, EventArgs e)
{
this.dataGrid1.DataSource = null;
for (int i = 0; i < 10000; i++)
{
DataRow newRow = dt.NewRow();
newRow["column2"] = "test";
dt.Rows.Add(newRow);
}
this.dataGrid1.DataSource = dt;
}
In .Net2.0, .Net Winform added bindingSource control, which we can set
RaiseListChangedEvents property to false to suspend the databinding code.
DataTable dt;
private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add(new DataColumn("column1", typeof(int)));
dt.Columns.Add(new DataColumn("column2", typeof(string)));
for (int i = 0; i < 5; i++)
{
DataRow dr = dt.NewRow();
dr["column1"] = i;
dr["column2"] = "item" + i.ToString();
dt.Rows.Add(dr);
}
this.dataGridView1.DataSource = this.bindingSource1;
this.bindingSource1.DataSource=dt;
}
private void button1_Click(object sender, EventArgs e)
{
this.bindingSource1.RaiseListChangedEvents = false;
for (int i = 0; i < 10000; i++)
{
DataRow newRow = dt.NewRow();
newRow["column2"] = "test";
dt.Rows.Add(newRow);
}
this.bindingSource1.RaiseListChangedEvents = true;
this.bindingSource1.ResetBindings(false);
}
If you want to know more details regarding Winform databinding, please
refer to the link below(please search "Provides centralized control for
binding operations" section in the doc to find the official comment
http://www.windowsforms.net/Samples/Go%20To%20Market/Data%20Binding/DataBind
ing%20FAQ.doc
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
That worked perfectly! I could not think of the keywords to find
this trick.
Thanks,
Submitted via EggHeadCafe - Software Developer Portal of Choice
AJAX Web Service Driven Customers Table With Customer Details
http://www.eggheadcafe.com/tutorials/aspnet/4c3d2726-d99e-4f83-9e49-0d4867b6271a/ajax-web-service-driven-customers-table-with-customer-details.aspx