How to return value in Combobox

  • Thread starter Thread starter Scotty
  • Start date Start date
S

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
 
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
 
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.
 
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.
 
both does not work
On cboTypeAdres_SelectedIndexChanged the index value goes into
txtTypeAdress

Only after i select manualy txtTypeAdress the update function will
succeed
 
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.
 
Back
Top