Home All Groups Group Topic Archive Search About
Author
6 Jan 2006 2:25 PM
Danny
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.

--
Danny

Author
6 Jan 2006 3:03 PM
Cor Ligthert [MVP]
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


Show quote
"Danny" <dansacsinc.com@newsgroup.nospam> schreef in bericht
news:FB5102F7-DCA3-4D28-9D43-360373C338A2@microsoft.com...
>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.
>
> --
> Danny
Author
6 Jan 2006 3:25 PM
Danny
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.
--
Danny


Show quote
"Cor Ligthert [MVP]" wrote:

> 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
>
>
> "Danny" <dansacsinc.com@newsgroup.nospam> schreef in bericht
> news:FB5102F7-DCA3-4D28-9D43-360373C338A2@microsoft.com...
> >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.
> >
> > --
> > Danny
>
>
>
Author
6 Jan 2006 4:37 PM
Danny
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.
--
Danny


Show quote
"Cor Ligthert [MVP]" wrote:

> 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
>
>
> "Danny" <dansacsinc.com@newsgroup.nospam> schreef in bericht
> news:FB5102F7-DCA3-4D28-9D43-360373C338A2@microsoft.com...
> >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.
> >
> > --
> > Danny
>
>
>

AddThis Social Bookmark Button