Event not firing

M

Mark Chambers

Hi there,

Does anyone know why the "ColumnChanged" event isn't fired when "Merge()" is
called below. "OnRowChanged()" is fired however: Thanks in advance.

private static void Test()
{
DataSet ds1 = new DataSet();
DataTable dt1 = ds1.Tables.Add("MyTable");
DataColumn primaryKeyColumn = dt1.Columns.Add("Key", typeof(int));
dt1.PrimaryKey = new DataColumn[] { primaryKeyColumn };
dt1.Columns.Add("Name", typeof(string));
DataRow dr1 = dt1.Rows.Add(1, "John");
ds1.AcceptChanges();

DataSet ds2 = ds1.Copy();
ds2.Tables["MyTable"].Rows[0]["Name"] = "David";

dt1.RowChanged += OnRowChanged;
dt1.ColumnChanged += OnColumnChanged;
ds1.Merge(ds2);
}

private static void OnRowChanged(object sender, DataRowChangeEventArgs e)
{
}

private static void OnColumnChanged(object sender, DataColumnChangeEventArgs
e)
{
}
 
G

Guest

Not sure, but it looks to me like you added the event delegate wireup after
you added the new column. Shouldn't it be defined before?
Peter
 
M

Mark Chambers

Not sure, but it looks to me like you added the event delegate wireup
after
you added the new column. Shouldn't it be defined before?

Thanks for the feedback but I'm not sure I follow you. Are you saying I
should assign the event before adding the column? I tried it just to be on
the safe side and the results are the same. I don't see why it should make
any difference however. You can normally hook/unhook an event anytime AFAIK
and I would have been surprised if it did work. It look like something's
just broken on MSFT's side but I'm still hoping to be proved wrong (and
would be happy to take the blame if someone can show me what I am doing
wrong).
 
M

Mark Chambers

I don't know, I only looked at your code sample briefly. Are you sure the
ColumnChanged event is actually supposed to be fired when you call Merge?

Unfortunately, the docs aren't entirely clear but AFAICT it should be. If
you change a field's value in a "DataTable" record it's supposed to fire to
indicate which field (column) has changed. It works if you change the value
directly in the record itself which is how most will usually rely on it. It
doesn't work when you merge your changes however but it should in theory.
The "RowChanged" event works that is (as previously noted) so
"ColumnChanged" should work as well. You would expect it to.
 
M

Mark Chambers

Unfortunately, the docs aren't entirely clear but AFAICT it should be. If
you change a field's value in a "DataTable" record it's supposed to fire
to indicate which field (column) has changed. It works if you change the
value directly in the record itself which is how most will usually rely on
it. It doesn't work when you merge your changes however but it should in
theory. The "RowChanged" event works that is (as previously noted) so
"ColumnChanged" should work as well. You would expect it to.

Ok, MSFT has now confirmed this is a bug and has submitted it for repair.
Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top