Home All Groups Group Topic Archive Search About

DataBinding problem - CurrencyManager Position is always equals to -1

Author
16 Nov 2005 3:51 PM
John Yung
Hi,

My program binds several controls on a WinForm to a Data Table via CurrencyManager.

Example:

   txtComment.DataBindings.Add("Text", _currentDS.WithholdingTax, "Comment");
   txtComment.DataBindings[0].Parse += new ConvertEventHandler(frmMain_Parse);

   ....

   _cmCurrentRecord = (CurrencyManager)this.BindingContext[_currentDS.WithholdingTax];


The data in Data Table is retrieve via a remote call to a business object. After the data is retrieve, I call the Refresh method on the currency manager.

Before I move to .NET 2.0, the values on the form would be refresh. However, since I moved to .NET 2.0, the values no longer refresh on the screen.

After I did some debugging, I noticed the Position value of the currency manager is always at -1. So before I call the Refresh method on the currency manager, I manually set the position value to 0 (the first record on the datatable, and I vertified the record exist on the datatable). That did not help, the position value is still equals to 0.

Anyone know why this happens?

Thanks,

John Yung

Author
16 Nov 2005 5:33 PM
Bart Mermuys
Hi,

Show quote
>"John Yung" <jo***@sac.com> wrote in message
>news:uSZ5fWs6FHA.3416@TK2MSFTNGP15.phx.gbl...
>Hi,

>My program binds several controls on a WinForm to a Data Table via
>CurrencyManager.
>
>Example:
>
> txtComment.DataBindings.Add("Text", _currentDS.WithholdingTax, "Comment");
>  txtComment.DataBindings[0].Parse += new
> ConvertEventHandler(frmMain_Parse);
>
>   ....
>
>   _cmCurrentRecord =
> (CurrencyManager)this.BindingContext[_currentDS.WithholdingTax];
>
>
>The data in Data Table is retrieve via a remote call to a business object.
>After
>the data is retrieve, I call the Refresh method on the currency manager.

>Before I move to .NET 2.0, the values on the form would be refresh.
>However,
>since I moved to .NET 2.0, the values no longer refresh on the screen.

Do you actually fill _currentDS.WithholdingTax or assign a new DataSet to
_currentDS ?  If you fill it then the CurrencyManager should automatically
refresh but if you assign a new DataSet then i don't see how any refresh
will help, you will need to rebind the controls.

>After I did some debugging, I noticed the Position value of the currency
>manager is
> always at -1. So before I call the Refresh method on the currency manager,
> I manually
>set the position value to 0 (the first record on the datatable, and I
>vertified the record exist
>on the datatable). That did not help, the position value is still equals to
>0.

If Count == -1 then the underlying DataSource doesn't contain any rows.

HTH,
Greetings

Show quote
>Anyone know why this happens?


>Thanks,

>John Yung
Author
18 Nov 2005 4:58 PM
John Yung
All,

I found the cause of the problem. When I made a call to the business tier
(via .NET remoting on a separate computer) to returne a new dataset, all the
binding information is gone. I guess that the binding information is not
been kept when you retrieve a dataset over .NET remoting. (I did not
experience the same problem when the business tier is run locally).

As a result, the data source for the currency manager is null. Thus,
CurrencyManager's position value is always equals to -1.

Thanks,

JY



Show quote
"Bart Mermuys" <bmermuys.nospam@hotmail.com> wrote in message
news:%23rzHlQt6FHA.1720@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> >"John Yung" <jo***@sac.com> wrote in message
> >news:uSZ5fWs6FHA.3416@TK2MSFTNGP15.phx.gbl...
> >Hi,
>
> >My program binds several controls on a WinForm to a Data Table via
> >CurrencyManager.
> >
> >Example:
> >
> > txtComment.DataBindings.Add("Text", _currentDS.WithholdingTax,
"Comment");
> >  txtComment.DataBindings[0].Parse += new
> > ConvertEventHandler(frmMain_Parse);
> >
> >   ....
> >
> >   _cmCurrentRecord =
> > (CurrencyManager)this.BindingContext[_currentDS.WithholdingTax];
> >
> >
> >The data in Data Table is retrieve via a remote call to a business
object.
> >After
> >the data is retrieve, I call the Refresh method on the currency manager.
>
> >Before I move to .NET 2.0, the values on the form would be refresh.
> >However,
> >since I moved to .NET 2.0, the values no longer refresh on the screen.
>
> Do you actually fill _currentDS.WithholdingTax or assign a new DataSet to
> _currentDS ?  If you fill it then the CurrencyManager should automatically
> refresh but if you assign a new DataSet then i don't see how any refresh
> will help, you will need to rebind the controls.
>
> >After I did some debugging, I noticed the Position value of the currency
> >manager is
> > always at -1. So before I call the Refresh method on the currency
manager,
> > I manually
> >set the position value to 0 (the first record on the datatable, and I
> >vertified the record exist
> >on the datatable). That did not help, the position value is still equals
to
> >0.
>
> If Count == -1 then the underlying DataSource doesn't contain any rows.
>
> HTH,
> Greetings
>
> >Anyone know why this happens?
>
>
> >Thanks,
>
> >John Yung
>
>

AddThis Social Bookmark Button