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 / .NET Framework / ADO.NET / January 2006

Tip: Looking for answers? Try searching our database.

Databinding Combobox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Danny - 06 Jan 2006 14:25 GMT
I want to start using databinding in a new winforms application.  I am using
VB.Net 2003.  The database has several fields that contain a numeric code
that translates to a text status.  For example 1=Open, 2=Closed, etc.  

I would like to bind this field to a dropdown combo box.  I need the
combobox to display Open, Closed, etc based on the numeric value in the
datarow.  Based on their selection, I need the underlying datarow to get a
numeric value returned base on their selection.

Can someone point me to an example of intercepting the bound data before it
gets to a control so that I can change the value and doing the reverse when
it changes in the control.

Signature

Danny

Cor Ligthert [MVP] - 06 Jan 2006 15:03 GMT
Danny,

This is very basic in binding to a complex datacontrol what the combobox is.

combobox1.datasource = TheDataTable
combobox1.displaymember = "TheFieldToDisplay" "open etc
combobox1.valuemember = "TheFieldToUse" '1 2 3

You use the index change event to get what is changed.
Be aware that the first time you protect that with a switch or on another
way.
As soon as you set something to a combobox the indexchange event will be
fired (as it will with every control with an index

I hope this gives some idea's

Cor

>I want to start using databinding in a new winforms application.  I am
>using
[quoted text clipped - 11 lines]
> when
> it changes in the control.
Danny - 06 Jan 2006 15:25 GMT
Thank you for the reply.  I understand the combobox1.valuemember .  This is
the field that contains the numeric value. (1, 2, 3, etc).

Also understand that combobox1.displaymember is the field that should be
displayed.  My problem is that the underlying datarow does not have the words
"Open, Closed", etc.  It only contains the numeric value.  

How do I associate the words "Open, Closed", with the combobox.  I need for
the combo box to show "Open", when a 1 is in the database field.  I also need
the dropdown list to contain all of the options for this field.
Signature

Danny

> Danny,
>
[quoted text clipped - 29 lines]
> > when
> > it changes in the control.
Danny - 06 Jan 2006 16:37 GMT
After some additional research it looks like I will need to create an
internal table or class/collection that has my options along with the
corresponding numeric value.  I will bind the combo box to that table /
collection.  I will set the display member to the "text" and the value member
to the "number".  

It looks like I will then need to add a binding back to my dataset ---
something like
comboBoxState.DataBindings.Add("SelectedValue",custdataset, "Invoice.Status")

I will give this a try.
Signature

Danny

> Danny,
>
[quoted text clipped - 29 lines]
> > when
> > it changes in the control.

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.