CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651

    Combobox.Items.Clear not working!

    I load a Combobox with the following code:

    Code:
    Public colCustomers As List(Of Customers) = Nothing
    
    Public Sub LoadCustomers(ByVal cbx As ComboBox)
            
         If colCustomers Is Nothing Then
              colCustomers = LoadCustomerList()
         End If
    
         cbx.Items.Clear()
    
         For Each Customer In colCustomers
              'Code to Add Customers
         Next
           
    End Sub
    I need to be able to call this function again and have it clear the combobox and reload the Customer List into it. However, when I call the function a second time, it leaves the name of the last Customer that was selected. cbx.SelectedIndex = -1, but cbx.Text = "Customer Name". I need this combobox to be completely cleared out with nothing selected and nothing displayed. Why doesn't cbx.Items.Clear clear the cbx completely?
    I'd rather be wakeboarding...

  2. #2
    Join Date
    May 2008
    Posts
    224

    Re: Combobox.Items.Clear not working!

    I haven't paid much attention to the combo box in dot net but in vb 6 it has a style property that prevents text which is not in the list, If memory serves it defaults to combo and needs to be changed to drop down list to achive what you are looking for. Of course dot net may be different but it is something to take a look at.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Combobox.Items.Clear not working!

    malleyo, you can set the DropDownStyle property of the ComboBox to DropDownList, that should work

  4. #4
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651

    Re: Combobox.Items.Clear not working!

    It worked! Thanks!
    I'd rather be wakeboarding...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured