Right now I have this code . It works fine unless I bind those comboboxes to arrays. any other solutions ?
ThanksVB Code:
Dim ComBox As Control For Each ComBox In ME.Controls If TypeOf ComBox Is ComboBox Then ComBox.Text = "" End If Next
Printable View
Right now I have this code . It works fine unless I bind those comboboxes to arrays. any other solutions ?
ThanksVB Code:
Dim ComBox As Control For Each ComBox In ME.Controls If TypeOf ComBox Is ComboBox Then ComBox.Text = "" End If Next
Is your goal just to clear the .Text property of each combobox, or to actually clear their items? I just wrote a little project that does what it sounds like you're doing, sets ComboBox1.DataSource to an array of strings, and made a button whose event runs the code you posted - and it works fine. :confused:
Not exactly what I need but I may need to set selectedindex property to specific item . It's good suggestion by the way .
VB Code:
Dim ComBox As Control For Each ComBox In ME.Controls If TypeOf ComBox Is ComboBox Then ComBox.SelectedItem=Nothing 'or 'ComBox.SelectedIndex=-1 End If Next
I've tried that already . Gave me this error "SelectedItem' is not a member of 'System.Windows.Forms.Control'"
Seems to me the only reason you'd get that is if your If condition isn't quite right? All comboboxes expose a .SelectedItem and .SelectedIndex property, whatever their values might be.
Ahh then you have to cast it to a combobox specifically:
VB Code:
Dim ComBox As Control For Each ComBox In Me.Controls If TypeOf ComBox Is ComboBox Then Try 'if not bound ComBox.Text = "" 'if bound DirectCast(ComBox, ComboBox).SelectedIndex = -1 Catch End Try End If Next
I'm talking about the above code . Have you tried it and got it to work (you or Edneeis)?Quote:
Originally posted by Edneeis
VB Code:
Dim ComBox As Control For Each ComBox In ME.Controls If TypeOf ComBox Is ComboBox Then ComBox.SelectedItem=Nothing 'or 'ComBox.SelectedIndex=-1 End If Next
This works fine Edneeis . Thanks :D