CurrencyManager marks all rows as Modified during navigation

G

Guest

Hello,

When I navigate a table in a dataset using CurrencyManager, each row that
has been navigated/selected/scrolled-through is marked with a RowState of
'Modified'.

Of course, all of the rows are updated even though no row data has changed
when DataAdapter.Update is invoked. This occurs regardless of field type.

Other than unchanged rows being marked as Modified, the CurrencyManager
functions as expected.

Details:

1) CurrencyManager is instantiated and bound at runtime.
2) CurrencyManager.Postion property is used for navigation.
3) Basic controls are bound to a dataset.
4) News data rows are added without incident.
5) Data rows can be deleted without incident.
6) Any row that is selected using CurrencyManager.Position has its RowState
changed to 'Modified'.
7) CurrencyManager.SuspendBinding() and CurrencyManager.ResumeBinding()
methods are used.

I'm sure it's something simple, but I haven't caught it.

Need a little here..... :p
Thanks
 
B

Bart Mermuys

Hi,

Digital Slug said:
Hello,

When I navigate a table in a dataset using CurrencyManager, each row that
has been navigated/selected/scrolled-through is marked with a RowState of
'Modified'.

Of course, all of the rows are updated even though no row data has changed
when DataAdapter.Update is invoked. This occurs regardless of field type.

Other than unchanged rows being marked as Modified, the CurrencyManager
functions as expected.

Details:

1) CurrencyManager is instantiated and bound at runtime.

Not sure what you mean by that, you don't bind a CurrencyManager.
2) CurrencyManager.Postion property is used for navigation.
3) Basic controls are bound to a dataset.
4) News data rows are added without incident.
5) Data rows can be deleted without incident.
6) Any row that is selected using CurrencyManager.Position has its
RowState
changed to 'Modified'.
7) CurrencyManager.SuspendBinding() and CurrencyManager.ResumeBinding()
methods are used.

I'm sure it's something simple, but I haven't caught it.

I'm not entirely sure if your scenario fits this, but most of the time this
is caused by binding to a Control property that doesn't have a similar named
changed event (eg. Text , TextChanged). Most of the standard Control
properties you want to bind to have such an event. Which Control properties
are you binding ?

HTH,
Greetings
 
G

Guest

Hello,
1) CurrencyManager is instantiated and bound at runtime.
Not sure what you mean by that, you don't bind a CurrencyManager.

I mispoke....
I instantiate the CurrencyManager using the Bindingcontext.

genericCurrencyManager =
(System.Windows.Forms.CurrencyManager)this.BindingContext[this.MY_DATASET,
MY_DATASET_TABLE_NAME];

Nothing out of the ordinary...nothing more....

I get the same "Modified Row" scenario regardless if I use custom controls
or generic controls. Originally, I though this problem was caused by my
custom controls, but this is not the case.

It occurs when:

Generic Controls added to a Form - (TextBox, DataTimePicker, ComboBoxes)
-And-
Custom Controls placed on a Form - Custom controls incorporate TextBox,
DataTimePicker, ComboBox, etc.
Most of the standard Control
properties you want to bind to have such an event. Which Control properties
are you binding ?

As mentioned above, it happens when I bind to a simple TextBox on a form and
when I bind to generic controls included in Custom (User) Controls. In regard
to custom control binding, I provide properties that expose the underlying
control.

Example:

public string FirstName
{
get{return firstName.Text;}
set{firstName.Text = value;}
}

QUESTION 1: Do I need to expose or trigger events as well?
Again, I have the same problem if I drop a textbox directly onto a form
(bypassing the custom controls altogether).

QUESTION 2: Should I expect the same of different results if I unbind all
controls and simply toggle through all datarows using
CurrencyManager.Position?

Thank you for you help and suggestions.
 
B

Bart Mermuys

Hi,

Digital Slug said:
Hello,
1) CurrencyManager is instantiated and bound at runtime.
Not sure what you mean by that, you don't bind a CurrencyManager.

I mispoke....
I instantiate the CurrencyManager using the Bindingcontext.

genericCurrencyManager =
(System.Windows.Forms.CurrencyManager)this.BindingContext[this.MY_DATASET,
MY_DATASET_TABLE_NAME];

Nothing out of the ordinary...nothing more....

I get the same "Modified Row" scenario regardless if I use custom controls
or generic controls. Originally, I though this problem was caused by my
custom controls, but this is not the case.

It occurs when:

Generic Controls added to a Form - (TextBox, DataTimePicker, ComboBoxes)
-And-
Custom Controls placed on a Form - Custom controls incorporate TextBox,
DataTimePicker, ComboBox, etc.

But you don't mention what properties you are binding, assuming we are
talking about the most used ones: TextBox.Text, DateTimePicker.Value/Text,
ComboBox.Text/SelectedIndex/SelectedValue/SelectedItem, then your problem
should definitely not occur.
As mentioned above, it happens when I bind to a simple TextBox on a form
and
when I bind to generic controls included in Custom (User) Controls. In
regard
to custom control binding, I provide properties that expose the underlying
control.

Example:

public string FirstName
{
get{return firstName.Text;}
set{firstName.Text = value;}
}

QUESTION 1: Do I need to expose or trigger events as well?

Yes, you do. Something like:

public class SomeUserControl : UserControl
{
// carefull not to forget the event keyword, it won't
// cause any errors, but it won't work either
public event EventHandler FirstNameChanged;

public string FirstName
{
get { return firstName.Text; }
set { firstName.Text = value; }
}

// add eventhandler to firstName.TextChanged
private void firstName_TextChanged(object Sender, EventArgs e)
{
if ( FirstNameChanged != null )
FirstNameChanged( this, EventArgs.Empty );
}

}
Again, I have the same problem if I drop a textbox directly onto a form
(bypassing the custom controls altogether).

Are you really sure ... it's a bit coincidental you have been using
UserControls.
QUESTION 2: Should I expect the same of different results if I unbind all
controls and simply toggle through all datarows using
CurrencyManager.Position?

If you unbind all Control properties then your problem shouldn't occur.
There might be a chance something else is causing this (can't think of
anything right now). Nevertheless if the cause would be something else then
you still need to implement the [PropName]Changed events on the UserControls
or you will have it again.

HTH,
Greetings
 
G

Guest

Hello again,

Yes, you were correct. I was not managing the code in my user controls
correctly. The problem only manifests itself in the custom controls.


Thanks or your help,
DS



Bart Mermuys said:
Hi,

Digital Slug said:
Hello,
1) CurrencyManager is instantiated and bound at runtime.
Not sure what you mean by that, you don't bind a CurrencyManager.

I mispoke....
I instantiate the CurrencyManager using the Bindingcontext.

genericCurrencyManager =
(System.Windows.Forms.CurrencyManager)this.BindingContext[this.MY_DATASET,
MY_DATASET_TABLE_NAME];

Nothing out of the ordinary...nothing more....

I get the same "Modified Row" scenario regardless if I use custom controls
or generic controls. Originally, I though this problem was caused by my
custom controls, but this is not the case.

It occurs when:

Generic Controls added to a Form - (TextBox, DataTimePicker, ComboBoxes)
-And-
Custom Controls placed on a Form - Custom controls incorporate TextBox,
DataTimePicker, ComboBox, etc.

But you don't mention what properties you are binding, assuming we are
talking about the most used ones: TextBox.Text, DateTimePicker.Value/Text,
ComboBox.Text/SelectedIndex/SelectedValue/SelectedItem, then your problem
should definitely not occur.
As mentioned above, it happens when I bind to a simple TextBox on a form
and
when I bind to generic controls included in Custom (User) Controls. In
regard
to custom control binding, I provide properties that expose the underlying
control.

Example:

public string FirstName
{
get{return firstName.Text;}
set{firstName.Text = value;}
}

QUESTION 1: Do I need to expose or trigger events as well?

Yes, you do. Something like:

public class SomeUserControl : UserControl
{
// carefull not to forget the event keyword, it won't
// cause any errors, but it won't work either
public event EventHandler FirstNameChanged;

public string FirstName
{
get { return firstName.Text; }
set { firstName.Text = value; }
}

// add eventhandler to firstName.TextChanged
private void firstName_TextChanged(object Sender, EventArgs e)
{
if ( FirstNameChanged != null )
FirstNameChanged( this, EventArgs.Empty );
}

}
Again, I have the same problem if I drop a textbox directly onto a form
(bypassing the custom controls altogether).

Are you really sure ... it's a bit coincidental you have been using
UserControls.
QUESTION 2: Should I expect the same of different results if I unbind all
controls and simply toggle through all datarows using
CurrencyManager.Position?

If you unbind all Control properties then your problem shouldn't occur.
There might be a chance something else is causing this (can't think of
anything right now). Nevertheless if the cause would be something else then
you still need to implement the [PropName]Changed events on the UserControls
or you will have it again.

HTH,
Greetings


Thank you for you help and suggestions.
 

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