Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15394

Problem with combo box with its Style property set to "0 - Dropdown combo"

$
0
0
I have a combo box with its Style property set to "0 - Dropdown combo".
Storing its value to the database poses a strange problem.

Let's say I have a combo box with its Style property set to "0 - Dropdown combo"
And I populate it like this:
Code:

Private Sub Form_Load()
  ......
  cbo1.Clear
  cbo1.AddItem "One"
  cbo1.AddItem "Two"
  cbo1.AddItem "Three"
  ......
End Sub

Then let's say for a specific record, I read its value from the database and show it like this (for simplicity I am hard-coding the value instead of actually reading it from database):
Code:

  cbo1.Text = "Two"
Then I click on this button:
Code:

Private Sub cmdProcList1_Click()
  Dim s                        As String
 
  s = ""
  s = s & "cbo1.ListCount = " & cbo1.ListCount & vbCrLf
  s = s & "cbo1.ListIndex = " & cbo1.ListIndex & vbCrLf
  s = s & "cbo1.Text = " & cbo1.Text & vbCrLf
  s = s & "cbo1.List(cbo1.ListIndex) = " & cbo1.List(cbo1.ListIndex) & vbCrLf
 
  s = s & ""
 
  Text3.Text = s
End Sub

Here is the result:
Quote:

cbo1.ListCount = 3
cbo1.ListIndex = -1
cbo1.Text = Two
cbo1.List(cbo1.ListIndex) =

As you see, the ListIndex is -1.
But, I expect it to be 1

What is wrong in here?
And how can I fix it?

Thanks

Viewing all articles
Browse latest Browse all 15394

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>