Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xxdoc/547a6622f1cb88130768da4db4eebb51 to your computer and use it in GitHub Desktop.
Save xxdoc/547a6622f1cb88130768da4db4eebb51 to your computer and use it in GitHub Desktop.
VB6,ComboBox,ListIndex
' #
' # 依值設定ComboBox.ListIndex
' # VB6的Combox的操作實在不人性,只好讓它人性一些些。
' # ref → http://stackoverflow.com/questions/18422210/vb6-select-combobox-text-value-based-on-database-data
' # 假設combox的list放資料的格式為:<value>.<dispaly_name>
' # eg. "0001.我是一號", "0002.我是二號二號", "0003.我是三號三號三號"
' # code → CombobBox_SetListIndexWithValue myCombox, "0002"
' #
Public Sub CombobBox_SetListIndexWithValue(cboData As ComboBox, value As String, Optional intCboLen As Integer = 4)
' find the ListIndex in cboDAta
Dim idx, i As Integer
idx = -1
For i = 1 To cboData.ListCount ' Each itm In cboData.List
If value = Trim(Left(cboData.List(i), intCboLen)) Then
idx = i
Exit For
End If
Next
' set combobox ListIndex
cboData.ListIndex = idx
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment