案例:
我在表单中有一个commandbutton和一个未绑定的组合框(rowsourcetype:值列表-使用vba从另一个表单填充)。
目标:
当用户单击CommandButton时,组合框中要从此组合框中删除的选定项。
尝试:
我在commandbutton的click事件中使用了组合框的removietem方法,它需要删除项的索引。
为了得到所选项的索引,我尝试使用组合框的selected属性,遍历所有的组合框项,但是selected属性始终返回0,这是对所选项的无遗憾。
Private Sub bDelete_Click()
Dim i As Integer
For i = 0 To Me.cAnswered.ListCount - 1
If Me.cAnswered.Selected(i) = True Then
'MsgBox i
'Stop
Me.cAnswered.RemoveItem i
Exit For
End If
Next
Me.bDelete.Visible = (Me.cAnswered.ListCount > 0)
End Sub
你能告诉我怎样才能达到这个目标吗?