How do you avoid that events are thrown when updating a datatable?
I have been searching for a while on the internet for a way to update a DataTable and turning of the event notification while doing it. My research still have not gotten me an answer. The following code should work I thought, but it does not:
DataTable tb = new DataTable();
tb.Columns.Add(new DataColumn("id", System.Type.GetType("System.Decimal")));
tb.BeginLoadData();
tb.LoadDataRow(new Object[] {1}, false); // This row still throws the event.
tb.EndLoadData();
I have initiated the event handler accordingly:
tb.RowChanged += new DataRowChangeEventHandler(tb_RowChanged);
and in the method tb_RowChanged I still get the events. MSDN says the following on the BeginLoadData method:
"
Turns offnotification, index maintenance, and constraints while loading data."
Is this a bug
and in such case, is there a nice way to solv this problem? I.e. making the DataTable not throwing events.
SoftwareAndWhy wrote: |
| I have been searching for a while on the internet for a way to update a DataTable and turning of the event notification while doing it. My research still have not gotten me an answer. The following code should work I thought, but it does not: DataTable tb = new DataTable(); tb.Columns.Add(new DataColumn("id", System.Type.GetType("System.Decimal"))); tb.BeginLoadData(); tb.LoadDataRow(new Object[] {1}, false); // This row still throws the event. tb.EndLoadData(); I have initiated the event handler accordingly: tb.RowChanged += new DataRowChangeEventHandler(tb_RowChanged); and in the method tb_RowChanged I still get the events. MSDN says the following on the BeginLoadData method: "Turns off notification, index maintenance, and constraints while loading data." Is this a bug and in such case, is there a nice way to solv this problem? I.e. making the DataTable not throwing events. 
|
|
SoftwareAndWhy,
It would seem to me that this is a bug (I verified the documentation, and agree).
I would recommend filing a bug at:
http://lab.msdn.microsoft.com/productfeedback/Default.aspx
It will be placed in the bug system at MS, and they will be notified of it.
Hope this helps.
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com