From: mick on
I have a property "TotalCost" of type int and a TextBox "tbTotalCost" in the
main form "Form1"
and was wondering how to bind one to the other

tbTotalCost.DataBinding.Add("Text",this.TotalWinnings, erm);

First peram. should be Property Name but in the examples Ive seen it usually
has "Text". Guessing its because it is the Text property of the TextBox?

Second peram. should be object DataSource. That the propery?

Third should be DataMember. Erm...

Flailing around a bit as you can see.

mick

From: mick on
"mick" <coughcough(a)privacy.com> wrote in message
news:ubQiWIztKHA.928(a)TK2MSFTNGP04.phx.gbl...
>I have a property "TotalCost" of type int and a TextBox "tbTotalCost" in
>the main form "Form1"
> and was wondering how to bind one to the other
>
> tbTotalCost.DataBinding.Add("Text",this.TotalWinnings, erm);
>
> First peram. should be Property Name but in the examples Ive seen it
> usually
> has "Text". Guessing its because it is the Text property of the TextBox?
>
> Second peram. should be object DataSource. That the propery?
>
> Third should be DataMember. Erm...
>
> Flailing around a bit as you can see.


Thought tbTotalCost.DataBinding.Add("Text", this,TotalWinnings.ToString());
might work but no. Tried changing the propery ToalCost to a string still
nothing.
Get - "Cannot bind to the property or column 0 on the DataSource.
Parameter name: dataMember."

This might mean something to someone. Doesnt seem to say why it cant bind
so isnt really much help.

mick

From: Peter Duniho on
mick wrote:
> I have a property "TotalCost" of type int and a TextBox "tbTotalCost" in
> the main form "Form1"
> and was wondering how to bind one to the other
>
> tbTotalCost.DataBinding.Add("Text",this.TotalWinnings, erm);

Is the property you want to bind called "TotalCost"? Or "TotalWinnings"?

> First peram. should be Property Name but in the examples Ive seen it
> usually
> has "Text". Guessing its because it is the Text property of the TextBox?
>
> Second peram. should be object DataSource. That the propery?

No. It's the other object containing the property to which the "Text"
property of the "tbTotalCost" is bound.

> Third should be DataMember. Erm...

That would be the name of the property in the other object.

Based on the code you posted, perhaps you want something more like this:

tbTotalCost.DataBinding.Add("Text", this, "TotalWinnings");

Though, typically I'd expect data bindings to be used between two
different objects, not to bind a property of one object to some other
property of the same object.

Pete
From: mick on
"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> wrote in message
news:ezPy2XztKHA.5384(a)TK2MSFTNGP04.phx.gbl...
> mick wrote:
>> I have a property "TotalCost" of type int and a TextBox "tbTotalCost" in
>> the main form "Form1"
>> and was wondering how to bind one to the other
>>
>> tbTotalCost.DataBinding.Add("Text",this.TotalWinnings, erm);
>
> Is the property you want to bind called "TotalCost"? Or "TotalWinnings"?

Oops. There are actually two of them TotalCost and TotalWinnings. Cut and
Pasted the wrong one. Sorry.


>> First peram. should be Property Name but in the examples Ive seen it
>> usually
>> has "Text". Guessing its because it is the Text property of the TextBox?
>>
>> Second peram. should be object DataSource. That the propery?
>
> No. It's the other object containing the property to which the "Text"
> property of the "tbTotalCost" is bound.
>
>> Third should be DataMember. Erm...
>
> That would be the name of the property in the other object.
>
> Based on the code you posted, perhaps you want something more like this:
>
> tbTotalCost.DataBinding.Add("Text", this, "TotalWinnings");

This compiles but doesnt update the TextBox. Is there somethig else I should
be doing?

While I was waiting for an answer I actually tried adding a couple of
EventsHandlers
and triggering them in the setters. It works but not sure if that is how
people usually
go about it.

mick


From: Peter Duniho on
mick wrote:
> [...]
>> Based on the code you posted, perhaps you want something more like this:
>>
>> tbTotalCost.DataBinding.Add("Text", this, "TotalWinnings");
>
> This compiles but doesnt update the TextBox. Is there somethig else I
> should be doing?

It's not really possible to say for sure unless you post a concise but
complete code example, and explain exactly what you are hoping to
accomplish with the data binding.

Do note that for data binding to work, the objects involved have to
comply with one of the various data binding models supported. The data
binding docs go into more detail with respect to that.

Pete