|
-
Apr 18th, 2003, 11:30 AM
#1
Thread Starter
Sleep mode
Clear Comboboxes ?[Resolved]
Right now I have this code . It works fine unless I bind those comboboxes to arrays. any other solutions ?
VB Code:
Dim ComBox As Control
For Each ComBox In ME.Controls
If TypeOf ComBox Is ComboBox Then
ComBox.Text = ""
End If
Next
Thanks
Last edited by Pirate; Apr 18th, 2003 at 01:25 PM.
-
Apr 18th, 2003, 01:02 PM
#2
Fanatic Member
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.
-
Apr 18th, 2003, 01:09 PM
#3
Thread Starter
Sleep mode
Not exactly what I need but I may need to set selectedindex property to specific item . It's good suggestion by the way .
-
Apr 18th, 2003, 01:10 PM
#4
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
-
Apr 18th, 2003, 01:13 PM
#5
Thread Starter
Sleep mode
I've tried that already . Gave me this error "SelectedItem' is not a member of 'System.Windows.Forms.Control'"
-
Apr 18th, 2003, 01:16 PM
#6
Fanatic Member
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.
-
Apr 18th, 2003, 01:20 PM
#7
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
-
Apr 18th, 2003, 01:20 PM
#8
Thread Starter
Sleep mode
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
I'm talking about the above code . Have you tried it and got it to work (you or Edneeis)?
-
Apr 18th, 2003, 01:22 PM
#9
Thread Starter
Sleep mode
This works fine Edneeis . Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|