Home All Groups Group Topic Archive Search About

CurrencyManager marks all rows as Modified during navigation

Author
2 Feb 2007 6:53 PM
Digital Slug
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

Author
3 Feb 2007 12:17 PM
Bart Mermuys
Hi,

Show quote
"Digital Slug" <DigitalSlugnospamalias@newsgroups.nospam> wrote in message
news:43C15731-E6C3-4189-851D-A0295166B41F@microsoft.com...
> 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

Show quote
>
> Need a little here.....   :-P
> Thanks
>
Author
5 Feb 2007 5:33 PM
Digital Slug
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.
Author
5 Feb 2007 10:38 PM
Bart Mermuys
Hi,

Show quote
"Digital Slug" <DigitalSlugnospamalias@newsgroups.nospam> wrote in message
news:CB7450EE-185F-43DD-9638-99D4D6A2B932@microsoft.com...
> 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.

Show quote
>
>>  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?

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



Show quote
>
> Thank you for you help and suggestions.
>


>
Author
13 Feb 2007 5:15 AM
Digital Slug
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



Show quote
"Bart Mermuys" wrote:

> Hi,
>
> "Digital Slug" <DigitalSlugnospamalias@newsgroups.nospam> wrote in message
> news:CB7450EE-185F-43DD-9638-99D4D6A2B932@microsoft.com...
> > 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.
>
> >
> >>  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?
>
> 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.
> >
>
>
> >
>
>
>

AddThis Social Bookmark Button