我有一個多列組合框,現在嘗試搜索代碼一段時間,但無濟于事。
這是我的組合框看起來像:
emp_id emp_name
--------- ---------------
<blank> - Select -
1 James Bond
2 Jason Statham
3 Sylvester S.
4 Chuck Norris
其中 columnwidths = "0,100" 和 columnheads = False,所以它只會顯示 emp_name
我想要做的是,基于變數以編程方式從組合框中選擇并顯示一個專案
到目前為止,與我想要實作的最接近的邏輯是:
empSysID = 3 '~This is Sylvester S.
With .ComboBoxEmployee
For i = 0 To .ListCount - 1
If .Column(0, i) = empSysID Then
.Value = .List(i) '~Trying to select and display 'Sylvester S.' in combobox
Exit For
End If
Next i
End With
但我收到運行時錯誤“380”:無法設定值屬性。無效的屬性值。
先感謝您!
uj5u.com熱心網友回復:
您需要使用ListIndex:
empSysID = 3 '~This is Sylvester S.
With .ComboBoxEmployee
For i = 0 To .ListCount - 1
If .Column(0, i) = empSysID Then
.ListIndex = i
Exit For
End If
Next i
End With
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/339741.html
