DataBound UserControl Always Modifies DataRow Upon Focus

  • Thread starter Thread starter POPone
  • Start date Start date
P

POPone

I'm trying to create a UserControl that is databound using Bindable
Properties. I bind DataColumns to those properties. My problem is
that once the data is bound to the control, it immediately marks the
DataRowState as Modified whether or not any data was modified. Anyone
have any thoughts on this? Any help would be appreciated, Thanks in
advance!
 
That sounds suspicious indeed. I take it you've verified that before the
binding the RowState is unchanged and immediately upon binding the change is
happening. You may have something in your set accesor that's doing it but
you should probably check the usual culprits like the Format and Parse
events and see if anything is modifying the value unknowingly. If you post
the code for the control, I'll be glad to take a look at it.
 
Thanks for your response Ryan.

Basically it's like this. My UserControl includes the following:

public string empLName="";

//Makes this property bindable.
[System.ComponentModel.Bindable(true)]
public string employeeLName
{
get
{
return empLName;
}
set
{
empLName=value;
}
}

I bound the control in my form by:
this.myControl1.DataBindings.Add(new
System.Windows.Forms.Binding("employeeLName", this.dataSet11,
"Employees.FirstName"));

I fill the dataset and show everything in a datagrid. After loading,
first row is modified and everything else unchanged. I changed the
selected row in the DataGrid to any other row, now first row is
modified, the newly selected row is modified, and everything else is
unchanged.

Thanks again for your time and help!
 
Hi there,

I stumbled over the same issue a while ago. This is quite tricky:

Declare a public event of type EventHandler, that follows the naming
convention PropertynameChanged, in your case something like:

public event EventHandler EmployeeLNameChanged;

Inside DataBinding, a delegate will be registered to this event, at
least that's my impression.

Then, fire the event each time the value is set:

public string employeeLName
{
set
{
empLName=value;
if (EmployeeLNameChanged != null) {
EmployeeLNameChanged(this, EventArgs.Empty);
}
}
}

HTH

Kind regards,
Arno Huetter


Thanks for your response Ryan.

Basically it's like this. My UserControl includes the following:

public string empLName="";

//Makes this property bindable.
[System.ComponentModel.Bindable(true)]
public string employeeLName
{
get
{
return empLName;
}
set
{
empLName=value;
}
}

I bound the control in my form by:
this.myControl1.DataBindings.Add(new
System.Windows.Forms.Binding("employeeLName", this.dataSet11,
"Employees.FirstName"));

I fill the dataset and show everything in a datagrid. After loading,
first row is modified and everything else unchanged. I changed the
selected row in the DataGrid to any other row, now first row is
modified, the newly selected row is modified, and everything else is
unchanged.

Thanks again for your time and help!

W.G. Ryan eMVP said:
That sounds suspicious indeed. I take it you've verified that before the
binding the RowState is unchanged and immediately upon binding the change is
happening. You may have something in your set accesor that's doing it but
you should probably check the usual culprits like the Format and Parse
events and see if anything is modifying the value unknowingly. If you post
the code for the control, I'll be glad to take a look at it.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
 
P.S. Correction to what I said below, might well be you have to name
your event "employeeLNameChanged" (as your property name starts with a
lowercase character as well):

public event EventHandler employeeLNameChanged;
Hi there,

I stumbled over the same issue a while ago. This is quite tricky:

Declare a public event of type EventHandler, that follows the naming convention PropertynameChanged, in your case something like:

public event EventHandler EmployeeLNameChanged;

Inside DataBinding, a delegate will be registered to this event, at least that's my impression.

Then, fire the event each time the value is set:

public string employeeLName
{
set
{
empLName=value;
if (EmployeeLNameChanged != null) {
EmployeeLNameChanged(this, EventArgs.Empty);
}
}
}

HTH

Kind regards,
Arno Huetter

Thanks for your response Ryan.

Basically it's like this. My UserControl includes the following:

public string empLName="";

//Makes this property bindable.
[System.ComponentModel.Bindable(true)]
public string employeeLName
{
get
{
return empLName;
}
set
{
empLName=value;
}
}

I bound the control in my form by:
this.myControl1.DataBindings.Add(new
System.Windows.Forms.Binding("employeeLName", this.dataSet11,
"Employees.FirstName"));

I fill the dataset and show everything in a datagrid. After loading,
first row is modified and everything else unchanged. I changed the
selected row in the DataGrid to any other row, now first row is
modified, the newly selected row is modified, and everything else is
unchanged.

Thanks again for your time and help!

W.G. Ryan eMVP said:
That sounds suspicious indeed. I take it you've verified that before the
binding the RowState is unchanged and immediately upon binding the change is
happening. You may have something in your set accesor that's doing it but
you should probably check the usual culprits like the Format and Parse
events and see if anything is modifying the value unknowingly. If you post
the code for the control, I'll be glad to take a look at it.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
 
Back
Top