none
clearing Combobox RRS feed

  • Question

  • Hi, I need some help for which I cannot find the solution.

    On a Windowsform I use several comboxes (DropDownStyle = DropDownList)..

     

    After a certain procedure I want to "clear" the comboboxtext (set the property

    to "", which is the default) with:

     

    Private Sub IniVelden(ByVal container As Control)

    For Each ctl As Control In container.Controls

    If TypeOf ctl Is TextBox Then

    ctl.ResetText()

    End If

    If TypeOf ctl Is ComboBox Then

    ctl.ResetText()

    End If

    If TypeOf ctl Is RichTextBox Then

    ctl.ResetText()

    End If

    Next ctl

    end Sub

     

    It succeeds with the Textboxes and with the RichTextboxes. When the DropDownStyle of the combox

    = DropDown it succeeds too, but it fails when the DropDownStyle of the combox = DropDownList.

    (I need to use this last Style!)

     

    Has someone a glue ?

     

    regards, Ger.

     

    Monday, November 19, 2007 3:13 PM

Answers

  •  

    Hi, Ger,

     

    You can set the value of ComboBox.SelectedIndex property to -1. In your code, change

     

    If TypeOf ctl Is ComboBox Then

    ctl.ResetText()

    End If

     

    To:

    If TypeOf ctl Is ComboBox Then

    Dim cbx As ComboBox = CType(ctl, ComboBox)

    cbx.SelectedIndex = -1

    End If

     

    Hope this helps

     

    Xin

    Monday, November 19, 2007 6:05 PM
    Moderator

All replies

  •  

    Hi, Ger,

     

    You can set the value of ComboBox.SelectedIndex property to -1. In your code, change

     

    If TypeOf ctl Is ComboBox Then

    ctl.ResetText()

    End If

     

    To:

    If TypeOf ctl Is ComboBox Then

    Dim cbx As ComboBox = CType(ctl, ComboBox)

    cbx.SelectedIndex = -1

    End If

     

    Hope this helps

     

    Xin

    Monday, November 19, 2007 6:05 PM
    Moderator
  •  

    Dear Xin,

     

    It works perfectly... Thx so much for answering..

     

    regards, Ger.

     

    Monday, November 19, 2007 6:26 PM