Home All Groups Group Topic Archive Search About

How to return value in Combobox

Author
13 Sep 2006 10:01 AM
Scotty
Hi, I need some info

How to return the value from the database


My combobox
Me.cboTypeAdres.Items.Add("Type Adres")
Me.cboTypeAdres.Items.Add("Leverancier")
Me.cboTypeAdres.Items.Add("Klant")



the value in the database = 0 ; 1 or 2

How to return the text using the value index so that the view is the bounded
text ?



Many thanks in advance

Marc

Author
13 Sep 2006 12:43 PM
trevisc
If you don't have the ability to add the name to your Database table
then the best way to do it is set a variable equal to the combobox
SelectedIndex and send that.

Put something like this code in the click event of a btnSave:

Dim iAdresType as Integer

iAdresType = cboTypeAdres.SelectedIndex

SelectedIndex is zero based so you can put the combobox items in order
that they are on the database.

You could also use a Select Case statement that looks at the
cboTypeAdres.Text and sends the appropriate SelectedIndex.

Hope that helps!

trevisc



Scotty wrote:
Show quoteHide quote
> Hi, I need some info
>
> How to return the value from the database
>
>
> My combobox
> Me.cboTypeAdres.Items.Add("Type Adres")
> Me.cboTypeAdres.Items.Add("Leverancier")
> Me.cboTypeAdres.Items.Add("Klant")
>
>
>
> the value in the database = 0 ; 1 or 2
>
> How to return the text using the value index so that the view is the bounded
> text ?
>
>
>
> Many thanks in advance
>
> Marc
Author
13 Sep 2006 2:34 PM
Scotty
Hi trevish,

Thanks for your answer,
My realy question also =  how to bind directly to database, now i have a
textbox bound
Me.txtAdresType.DataBindings.Add("text", bsAdressen, "AdresType")

If I select my combo, the update in the textbox is working fine but if i
will save the data and the textbox hans't been selected the value return to
the previous old value.
How to fix?
Or how to databind the combobox   "cboTypeAdres"  direcly


best regards,
Marc.






Show quoteHide quote
"trevisc" <trev***@gmail.com> schreef in bericht
news:1158151433.155330.314030@i3g2000cwc.googlegroups.com...
> If you don't have the ability to add the name to your Database table
> then the best way to do it is set a variable equal to the combobox
> SelectedIndex and send that.
>
> Put something like this code in the click event of a btnSave:
>
> Dim iAdresType as Integer
>
> iAdresType = cboTypeAdres.SelectedIndex
>
> SelectedIndex is zero based so you can put the combobox items in order
> that they are on the database.
>
> You could also use a Select Case statement that looks at the
> cboTypeAdres.Text and sends the appropriate SelectedIndex.
>
> Hope that helps!
>
> trevisc
>
>
>
> Scotty wrote:
>> Hi, I need some info
>>
>> How to return the value from the database
>>
>>
>> My combobox
>> Me.cboTypeAdres.Items.Add("Type Adres")
>> Me.cboTypeAdres.Items.Add("Leverancier")
>> Me.cboTypeAdres.Items.Add("Klant")
>>
>>
>>
>> the value in the database = 0 ; 1 or 2
>>
>> How to return the text using the value index so that the view is the
>> bounded
>> text ?
>>
>>
>>
>> Many thanks in advance
>>
>> Marc
>
Author
13 Sep 2006 3:04 PM
trevisc
hmm..can you just put

cboTypeAdres.Focus() in the click event of the Save button?

still not sure if i'm understanding the problem but if by clicking in a
box it somehow refreshes your combo box then either do
cboTypeAdres.refresh or just set focus to the combobox before you run
the save routine.



Show quoteHide quote
> If I select my combo, the update in the textbox is working fine but if i
> will save the data and the textbox hans't been selected the value return to
> the previous old value.

>
>
>
>
> "trevisc" <trev***@gmail.com> schreef in bericht
> news:1158151433.155330.314030@i3g2000cwc.googlegroups.com...
> > If you don't have the ability to add the name to your Database table
> > then the best way to do it is set a variable equal to the combobox
> > SelectedIndex and send that.
> >
> > Put something like this code in the click event of a btnSave:
> >
> > Dim iAdresType as Integer
> >
> > iAdresType = cboTypeAdres.SelectedIndex
> >
> > SelectedIndex is zero based so you can put the combobox items in order
> > that they are on the database.
> >
> > You could also use a Select Case statement that looks at the
> > cboTypeAdres.Text and sends the appropriate SelectedIndex.
> >
> > Hope that helps!
> >
> > trevisc
> >
> >
> >
> > Scotty wrote:
> >> Hi, I need some info
> >>
> >> How to return the value from the database
> >>
> >>
> >> My combobox
> >> Me.cboTypeAdres.Items.Add("Type Adres")
> >> Me.cboTypeAdres.Items.Add("Leverancier")
> >> Me.cboTypeAdres.Items.Add("Klant")
> >>
> >>
> >>
> >> the value in the database = 0 ; 1 or 2
> >>
> >> How to return the text using the value index so that the view is the
> >> bounded
> >> text ?
> >>
> >>
> >>
> >> Many thanks in advance
> >>
> >> Marc
> >
Author
13 Sep 2006 3:15 PM
Scotty
both does not work
On  cboTypeAdres_SelectedIndexChanged    the index value goes into
txtTypeAdress

Only after  i select manualy    txtTypeAdress  the update function will
succeed





Show quoteHide quote
"trevisc" <trev***@gmail.com> schreef in bericht
news:1158159851.088146.192350@m73g2000cwd.googlegroups.com...
> hmm..can you just put
>
> cboTypeAdres.Focus() in the click event of the Save button?
>
> still not sure if i'm understanding the problem but if by clicking in a
> box it somehow refreshes your combo box then either do
> cboTypeAdres.refresh or just set focus to the combobox before you run
> the save routine.
>
>
>
>> If I select my combo, the update in the textbox is working fine but if i
>> will save the data and the textbox hans't been selected the value return
>> to
>> the previous old value.
>
>>
>>
>>
>>
>> "trevisc" <trev***@gmail.com> schreef in bericht
>> news:1158151433.155330.314030@i3g2000cwc.googlegroups.com...
>> > If you don't have the ability to add the name to your Database table
>> > then the best way to do it is set a variable equal to the combobox
>> > SelectedIndex and send that.
>> >
>> > Put something like this code in the click event of a btnSave:
>> >
>> > Dim iAdresType as Integer
>> >
>> > iAdresType = cboTypeAdres.SelectedIndex
>> >
>> > SelectedIndex is zero based so you can put the combobox items in order
>> > that they are on the database.
>> >
>> > You could also use a Select Case statement that looks at the
>> > cboTypeAdres.Text and sends the appropriate SelectedIndex.
>> >
>> > Hope that helps!
>> >
>> > trevisc
>> >
>> >
>> >
>> > Scotty wrote:
>> >> Hi, I need some info
>> >>
>> >> How to return the value from the database
>> >>
>> >>
>> >> My combobox
>> >> Me.cboTypeAdres.Items.Add("Type Adres")
>> >> Me.cboTypeAdres.Items.Add("Leverancier")
>> >> Me.cboTypeAdres.Items.Add("Klant")
>> >>
>> >>
>> >>
>> >> the value in the database = 0 ; 1 or 2
>> >>
>> >> How to return the text using the value index so that the view is the
>> >> bounded
>> >> text ?
>> >>
>> >>
>> >>
>> >> Many thanks in advance
>> >>
>> >> Marc
>> >
>
Author
13 Sep 2006 4:40 PM
trevisc
what about txtTypeAdress.focus() before you save?


Scotty wrote:
Show quoteHide quote
> both does not work
> On  cboTypeAdres_SelectedIndexChanged    the index value goes into
> txtTypeAdress
>
> Only after  i select manualy    txtTypeAdress  the update function will
> succeed
>
>
>
>
>
> "trevisc" <trev***@gmail.com> schreef in bericht
> news:1158159851.088146.192350@m73g2000cwd.googlegroups.com...
> > hmm..can you just put
> >
> > cboTypeAdres.Focus() in the click event of the Save button?
> >
> > still not sure if i'm understanding the problem but if by clicking in a
> > box it somehow refreshes your combo box then either do
> > cboTypeAdres.refresh or just set focus to the combobox before you run
> > the save routine.
> >
> >
> >
> >> If I select my combo, the update in the textbox is working fine but if i
> >> will save the data and the textbox hans't been selected the value return
> >> to
> >> the previous old value.
> >
> >>
> >>
> >>
> >>
> >> "trevisc" <trev***@gmail.com> schreef in bericht
> >> news:1158151433.155330.314030@i3g2000cwc.googlegroups.com...
> >> > If you don't have the ability to add the name to your Database table
> >> > then the best way to do it is set a variable equal to the combobox
> >> > SelectedIndex and send that.
> >> >
> >> > Put something like this code in the click event of a btnSave:
> >> >
> >> > Dim iAdresType as Integer
> >> >
> >> > iAdresType = cboTypeAdres.SelectedIndex
> >> >
> >> > SelectedIndex is zero based so you can put the combobox items in order
> >> > that they are on the database.
> >> >
> >> > You could also use a Select Case statement that looks at the
> >> > cboTypeAdres.Text and sends the appropriate SelectedIndex.
> >> >
> >> > Hope that helps!
> >> >
> >> > trevisc
> >> >
> >> >
> >> >
> >> > Scotty wrote:
> >> >> Hi, I need some info
> >> >>
> >> >> How to return the value from the database
> >> >>
> >> >>
> >> >> My combobox
> >> >> Me.cboTypeAdres.Items.Add("Type Adres")
> >> >> Me.cboTypeAdres.Items.Add("Leverancier")
> >> >> Me.cboTypeAdres.Items.Add("Klant")
> >> >>
> >> >>
> >> >>
> >> >> the value in the database = 0 ; 1 or 2
> >> >>
> >> >> How to return the text using the value index so that the view is the
> >> >> bounded
> >> >> text ?
> >> >>
> >> >>
> >> >>
> >> >> Many thanks in advance
> >> >>
> >> >> Marc
> >> >
> >
Author
14 Sep 2006 6:29 AM
Scotty
Hi, Ive found it, see code below
Many thx for your idea's
By adding the refrech to txtAdresType
Private Sub cboTypeAdres_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboTypeAdres.SelectedIndexChanged

Me.txtAdresType.Text = CStr(Me.cboTypeAdres.SelectedIndex)

Me.txtAdresType.Focus()

Me.txtAdresType.Refresh()

End Sub


Marc.




Show quoteHide quote
"trevisc" <trev***@gmail.com> schreef in bericht
news:1158165620.080373.5800@e3g2000cwe.googlegroups.com...
> what about txtTypeAdress.focus() before you save?
>
>
> Scotty wrote:
>> both does not work
>> On  cboTypeAdres_SelectedIndexChanged    the index value goes into
>> txtTypeAdress
>>
>> Only after  i select manualy    txtTypeAdress  the update function will
>> succeed
>>
>>
>>
>>
>>
>> "trevisc" <trev***@gmail.com> schreef in bericht
>> news:1158159851.088146.192350@m73g2000cwd.googlegroups.com...
>> > hmm..can you just put
>> >
>> > cboTypeAdres.Focus() in the click event of the Save button?
>> >
>> > still not sure if i'm understanding the problem but if by clicking in a
>> > box it somehow refreshes your combo box then either do
>> > cboTypeAdres.refresh or just set focus to the combobox before you run
>> > the save routine.
>> >
>> >
>> >
>> >> If I select my combo, the update in the textbox is working fine but if
>> >> i
>> >> will save the data and the textbox hans't been selected the value
>> >> return
>> >> to
>> >> the previous old value.
>> >
>> >>
>> >>
>> >>
>> >>
>> >> "trevisc" <trev***@gmail.com> schreef in bericht
>> >> news:1158151433.155330.314030@i3g2000cwc.googlegroups.com...
>> >> > If you don't have the ability to add the name to your Database table
>> >> > then the best way to do it is set a variable equal to the combobox
>> >> > SelectedIndex and send that.
>> >> >
>> >> > Put something like this code in the click event of a btnSave:
>> >> >
>> >> > Dim iAdresType as Integer
>> >> >
>> >> > iAdresType = cboTypeAdres.SelectedIndex
>> >> >
>> >> > SelectedIndex is zero based so you can put the combobox items in
>> >> > order
>> >> > that they are on the database.
>> >> >
>> >> > You could also use a Select Case statement that looks at the
>> >> > cboTypeAdres.Text and sends the appropriate SelectedIndex.
>> >> >
>> >> > Hope that helps!
>> >> >
>> >> > trevisc
>> >> >
>> >> >
>> >> >
>> >> > Scotty wrote:
>> >> >> Hi, I need some info
>> >> >>
>> >> >> How to return the value from the database
>> >> >>
>> >> >>
>> >> >> My combobox
>> >> >> Me.cboTypeAdres.Items.Add("Type Adres")
>> >> >> Me.cboTypeAdres.Items.Add("Leverancier")
>> >> >> Me.cboTypeAdres.Items.Add("Klant")
>> >> >>
>> >> >>
>> >> >>
>> >> >> the value in the database = 0 ; 1 or 2
>> >> >>
>> >> >> How to return the text using the value index so that the view is
>> >> >> the
>> >> >> bounded
>> >> >> text ?
>> >> >>
>> >> >>
>> >> >>
>> >> >> Many thanks in advance
>> >> >>
>> >> >> Marc
>> >> >
>> >
>