control data binding not happening when data entered from app

G

Guest

I have a textbox, which is bound to a class member:

textBoxDataServerhostname.DataBindings.Add("Text", localOptions,
"DataServerHostname");

The text can be entered by the user, or sometimes generated from code, for
example:
textBoxDataServerhostname.Text = anotherTextBox.Text;

When text is entered by the user, the class member is updated correctly;
when it's generated from code, the member is unchanged.

How do i get this to work (I want the member to change when the textbox is
changed from code)?

I have tried setting Modified = true, and setting ReadOnly = false (in the
case where the text is generated by code, the control is read only).

Thanks in advance for any help...
 
G

Guest

That has gotta be a record! You win the prize! Cheers...

for anyone reading this thread who is as paste-happy as
me: textBoxDataServerhostname.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();

So... anyone game to explain the underlying reason why this is the case?
Sijin Joseph said:
Try adding this line of code after setting the text throught code

textBoxServerhostname.Bindings["Text"].BindingManagerBase.EndCurrentEdit();

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
I have a textbox, which is bound to a class member:

textBoxDataServerhostname.DataBindings.Add("Text", localOptions,
"DataServerHostname");

The text can be entered by the user, or sometimes generated from code, for
example:
textBoxDataServerhostname.Text = anotherTextBox.Text;

When text is entered by the user, the class member is updated correctly;
when it's generated from code, the member is unchanged.

How do i get this to work (I want the member to change when the textbox is
changed from code)?

I have tried setting Modified = true, and setting ReadOnly = false (in the
case where the text is generated by code, the control is read only).

Thanks in advance for any help...
 
G

Guest

Another less critical question...

All the controls on the form are bound like so:
textBoxDataServerhostname.DataBindings.Add("Text", localOptions,
"DataServerHostname");
numericUpDownPort.DataBindings.Add("Value", localOptions, "Port");
[etc]

Is there a way, (e.g.) when the form is closed, to EndCurrentEdit on all of
them? e.g. something like:
Formclass.BindingContext.EndCurrentEdit()

Should I be setting up the bindings in a different way to make an operation
like that possible?

cheeeers again,
Rua HM.

Rua Haszard Morris said:
That has gotta be a record! You win the prize! Cheers...

for anyone reading this thread who is as paste-happy as
me: textBoxDataServerhostname.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();

So... anyone game to explain the underlying reason why this is the case?
Sijin Joseph said:
Try adding this line of code after setting the text throught code

textBoxServerhostname.Bindings["Text"].BindingManagerBase.EndCurrentEdit();

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
I have a textbox, which is bound to a class member:

textBoxDataServerhostname.DataBindings.Add("Text", localOptions,
"DataServerHostname");

The text can be entered by the user, or sometimes generated from code, for
example:
textBoxDataServerhostname.Text = anotherTextBox.Text;

When text is entered by the user, the class member is updated correctly;
when it's generated from code, the member is unchanged.

How do i get this to work (I want the member to change when the textbox is
changed from code)?

I have tried setting Modified = true, and setting ReadOnly = false (in the
case where the text is generated by code, the control is read only).

Thanks in advance for any help...
 
S

Sijin Joseph

Well the thing is, that the data gets sent to the source only when
EndCurrentEdit() is called. Typically this gets called in the
OnValidating() event of the control when you move focus away from the
control. Try moving focus away from the control and see if the data gets
commited, you may also use reflection to call the control.OnValidating()
method to get a similar effect.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
That has gotta be a record! You win the prize! Cheers...

for anyone reading this thread who is as paste-happy as
me: textBoxDataServerhostname.DataBindings["Text"].BindingManagerBase.EndCurrentEdit();

So... anyone game to explain the underlying reason why this is the case?
:

Try adding this line of code after setting the text throught code

textBoxServerhostname.Bindings["Text"].BindingManagerBase.EndCurrentEdit();

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
I have a textbox, which is bound to a class member:

textBoxDataServerhostname.DataBindings.Add("Text", localOptions,
"DataServerHostname");

The text can be entered by the user, or sometimes generated from code, for
example:
textBoxDataServerhostname.Text = anotherTextBox.Text;

When text is entered by the user, the class member is updated correctly;
when it's generated from code, the member is unchanged.

How do i get this to work (I want the member to change when the textbox is
changed from code)?

I have tried setting Modified = true, and setting ReadOnly = false (in the
case where the text is generated by code, the control is read only).

Thanks in advance for any help...
 

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