Skip to content

Instantly share code, notes, and snippets.

@relyky
Last active September 26, 2019 04:21
Show Gist options
  • Select an option

  • Save relyky/b0d13e7089b54d8e2b7d to your computer and use it in GitHub Desktop.

Select an option

Save relyky/b0d13e7089b54d8e2b7d 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