VB中单选按钮和组合框的一个小问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 05:26:19
大概是这样的,在两个单选按钮中,我选中其中一个,它的caption就添加到组合框中,而当选中另一个单选按钮,组合框中的刚才添加的内容被删除,而添加第二个按钮的caption,同时不影响组合框内的其他内容。谢谢

Private Sub Command1_Click()
If Option1.Value = True Then
If List1.List(List1.ListCount - 1) = Option2.Caption Then
List1.RemoveItem List1.ListCount - 1
End If
List1.AddItem Option1.Caption
ElseIf Option2.Value = True Then
If List1.List(List1.ListCount - 1) = Option1.Caption Then
List1.RemoveItem List1.ListCount - 1
End If
List1.AddItem Option2.Caption
End If
End Sub
你也可以把事件写到option1和2的click事件中。

Private Sub Option1_Click()
If Option1.Value = True Then Combo1.AddItem Option1.Caption
End Sub

Private Sub Option2_Click()
If Option2.Value = True Then
Combo1.RemoveItem (Combo1.ListCount - 1)
Combo1.AddItem Option2.Caption
End If
End Sub