Wednesday, March 4, 2009

Function to Clear all ComboBoxes in a form

Public Sub ClearComboBoxes(ByVal f As Form)

Dim meuForm As Type = f.GetType()
Dim campos As Reflection.FieldInfo() = meuForm.GetFields(Reflection.BindingFlags.Instance Or Reflection.BindingFlags.NonPublic)

For Each campo As Reflection.FieldInfo In campos
If campo.FieldType.Name.ToLower = "combobox" Then
Dim t As ComboBox = DirectCast(campo.GetValue(f), ComboBox)
t.Text = ""
t.SelectedIndex = -1
End If
Next


End Sub



NOTE: We can clear all controls within this function. Use proper select case to do all action.

No comments: