We help IT Professionals succeed at work.

ComboBox Collection Name in a Form

Moshe Singer
Moshe Singer asked
on
The following is the code I am using. I used ...... to indicate the part of code that it is missing. Can you fill me in?
       index= String of Name Of Combo
 
Dim ctl As System.Windows.Forms.ComboBox
        For Each ctl In .............
            If TypeOf ctl Is System.Windows.Forms.ComboBox Then
                If DirectCast(ctl, System.Windows.Forms.ComboBox).Name = index Then
                    DirectCast(ctl, System.Windows.Forms.ComboBox).Text = ""
                End If
            End If
        Next
Comment
Watch Question

Dim ctl As System.Windows.Forms.ComboBox
        For Each ctl In Control In me.Controls
            If TypeOf ctl Is System.Windows.Forms.ComboBox Then
                If DirectCast(ctl, System.Windows.Forms.ComboBox).Name = index Then
                    DirectCast(ctl, System.Windows.Forms.ComboBox).Text = ""
                End If
            End If
        Next
Moshe Singerdeveloper

Author

Commented:
i got s massage:
Unable to cast object of type 'System.Windows.Forms.TextBox' to type 'System.Windows.Forms.ComboBox'.
Please test it and see this massage
Dim ctl As System.Windows.Forms.Control
        For Each ctl In Me.Controls
            If TypeOf ctl Is System.Windows.Forms.ComboBox Then
                If DirectCast(ctl, System.Windows.Forms.ComboBox).Name = index Then
                    DirectCast(ctl, System.Windows.Forms.ComboBox).Text = ""
                End If
            End If
        Next