【发布时间】:2015-01-03 07:44:50
【问题描述】:
我的问题:
我有一个功能可以清除组框中的文本框和组合框 (DropDownList)。虽然文本框正在清除,但我无法清除组合框。
我的代码:
Public Sub ClearGroupControls()
For Each groupboxControl As Control In Me.Controls
If TypeOf groupboxControl Is GroupBox Then
For Each control As Control In groupboxControl.Controls
' Clear controls
If TypeOf control Is TextBox Then
control.Text = ""
ElseIf TypeOf control Is ComboBox Then
'control.Text = String.Empty
'control.SelectedIndex = -1
control.Text = ""
End If
Next
End If
Next
End Sub
注意:.SelectedIndex = -1 产生错误:
SelectedIndex 不是 System.Windows.Forms.Control 的成员
...考虑到 control.Text 在控件是 TextBox 时有效。
【问题讨论】:
-
这些组合的 DropDownStyle 是什么?
-
@Steve
DropDownList.
标签: vb.net visual-studio winforms combobox