469,616 Members | 2,517 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Event not firing

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)
{
}
May 21 '07 #1
6 2378
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
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mark Chambers" wrote:
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)
{
}
May 21 '07 #2
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).
May 22 '07 #3
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?

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mark Chambers" wrote:
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).
May 22 '07 #4
>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.
May 22 '07 #5
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.
May 23 '07 #6
Bully for you, if you found a legitimate bug. 99 out of 100 are simply user
stupidity, not bugs at all. Congratulations!
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Mark Chambers" wrote:
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.
May 24 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Brett | last post: by
1 post views Thread by Diana | last post: by
5 posts views Thread by jaysonnward | last post: by
6 posts views Thread by sjoshi | last post: by
2 posts views Thread by John Kotuby | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.