Get a value from a binding source

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I have a text box on my form that I've got set to read from from my binding
source, so when ever I mighlight a row, that text box has the row ID in it.
Now how do I assign that value to a variable for use in other area of my
program?

Thanks
 
Hi,

Jason said:
I have a text box on my form that I've got set to read from from my binding
source, so when ever I mighlight a row, that text box has the row ID in it.
Now how do I assign that value to a variable for use in other area of my
program?

Can you use the TextChanged event?
 
I'm not exactly sure what you mean.
I was hoping to do somthing like string x = testbox1.value; but I guess it's
not that simple.
 
Hi,
Jason said:
I'm not exactly sure what you mean.
I was hoping to do somthing like string x = testbox1.value; but I guess
it's not that simple.

And that is what you are going to do, inside the event handler

you do like:

textbox1.TextChanged += new EventHandler( mymethod);

void mymethod(object sender, EventArgs e)
{
string x = testbox1.value
}

something like that.
 
I have a text box on my form that I've got set to read from from my binding
source, so when ever I mighlight a row, that text box has the row ID in it.
Now how do I assign that value to a variable for use in other area of my
program?

Thus, you already have something as the following:

BindingSource bs = ...;
textBox1.Databindings.Add("Text", bs, "MyProperty");

Now, if you want to use this value elsewhere you have two options:

string alt1 = textBox1.Text;
string alt2 = (bs.Current as TheTypeOfYourObject).MyProperty.ToString();
 

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

Back
Top