S
svestin
Hi all!
It looks like I have some strange behaviour of the
DataRowView.PropertyChanged event.
In the windowsform example below I have a typed dataset (ds1) with one
table (Table1) that has one column (Col1).
Pressing the button btnTest, I add an event handler for the
PropertyChanged event for the DataRowView of the first row in Table1.
Then I change the value from "AAA" to "CCC".
Normally this results in a fired event (drvTest_PropertyChanged called)
However, if there's been a BindingSource that has its DataSource and
DataMember properties set, the event is NOT fired ??????
private void Form1_Load(object sender, EventArgs e)
{
//Two rows of test data
ds1.Table1.AddTable1Row("AAA");
ds1.Table1.AddTable1Row("BBB");
//Results in an event when btnTest pressed
//bindingSource1.DataSource = ds1.Table1.DefaultView;
//Results in an event when btnTest pressed
//bindingSource1.DataSource = ds1.Table1;
//But using these 2 lines results in NO event <===
bindingSource1.DataSource = ds1;
bindingSource1.DataMember = "Table1";
}
private void btnTest_Click(object sender, EventArgs e)
{
// Get the DataRowView from the first row
DataRowView drvTest = ds1.Table1.DefaultView[0];
//Add event handler for PropertyChanged (on the DataRowView
drvTest.PropertyChanged +=
new PropertyChangedEventHandler(drvTest_PropertyChanged);
// Change the first row (Col1); And this should fire an event
ds1.Table1[0]["Col1"] = "CCC";
// Use this line to change the value and there will be
// no events at all if the bindingSource1.DataSource is set.
//drvTest["Col1"] = "CCC";
}
void drvTest_PropertyChanged(object sender,
PropertyChangedEventArgs e)
{
MessageBox.Show("I got an event");
}
Anyone out there with any suggestions?
Can the DataRowView.PropertyChanged event be trusted?
Any important information that I have missed?
Regards
/Stefan Vestin
It looks like I have some strange behaviour of the
DataRowView.PropertyChanged event.
In the windowsform example below I have a typed dataset (ds1) with one
table (Table1) that has one column (Col1).
Pressing the button btnTest, I add an event handler for the
PropertyChanged event for the DataRowView of the first row in Table1.
Then I change the value from "AAA" to "CCC".
Normally this results in a fired event (drvTest_PropertyChanged called)
However, if there's been a BindingSource that has its DataSource and
DataMember properties set, the event is NOT fired ??????
private void Form1_Load(object sender, EventArgs e)
{
//Two rows of test data
ds1.Table1.AddTable1Row("AAA");
ds1.Table1.AddTable1Row("BBB");
//Results in an event when btnTest pressed
//bindingSource1.DataSource = ds1.Table1.DefaultView;
//Results in an event when btnTest pressed
//bindingSource1.DataSource = ds1.Table1;
//But using these 2 lines results in NO event <===
bindingSource1.DataSource = ds1;
bindingSource1.DataMember = "Table1";
}
private void btnTest_Click(object sender, EventArgs e)
{
// Get the DataRowView from the first row
DataRowView drvTest = ds1.Table1.DefaultView[0];
//Add event handler for PropertyChanged (on the DataRowView
drvTest.PropertyChanged +=
new PropertyChangedEventHandler(drvTest_PropertyChanged);
// Change the first row (Col1); And this should fire an event
ds1.Table1[0]["Col1"] = "CCC";
// Use this line to change the value and there will be
// no events at all if the bindingSource1.DataSource is set.
//drvTest["Col1"] = "CCC";
}
void drvTest_PropertyChanged(object sender,
PropertyChangedEventArgs e)
{
MessageBox.Show("I got an event");
}
Anyone out there with any suggestions?
Can the DataRowView.PropertyChanged event be trusted?
Any important information that I have missed?
Regards
/Stefan Vestin