Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Get a value from a binding source

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jason - 06 Sep 2007 14:19 GMT
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
Ignacio Machin ( .NET/ C# MVP ) - 06 Sep 2007 15:12 GMT
Hi,

>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?
Jason - 06 Sep 2007 15:32 GMT
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,
>
[quoted text clipped - 4 lines]
>
> Can you use the TextChanged event?
Ignacio Machin ( .NET/ C# MVP ) - 06 Sep 2007 15:59 GMT
Hi,
> 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.
Tim Van Wassenhove - 06 Sep 2007 19:35 GMT
> 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();

Signature

Kind regards,
Tim Van Wassenhove <url:http://www.timvw.be/>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.