Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I initially display my ComboBox, using the line ...

VB
ComboBox3.SelectedIndex = -1


... it displays as blank, as required.

However, when I have made a selection from that ComboBox and then Cancelled, so as to reset the form, the ComboBox does not display as blank but it retains the selection I previously made.

Any ideas why & how I can reset it to being Null ?

The code is as follows, fairly basic stuff :

VB
Public Sub Tab4_Selected()

    ComboBox3.Items.Clear()

    For Each Item In ComboBox1.Items
        With ComboBox3.Items
            .Add(Item)
        End With
    Next

    ComboBox3.Items.RemoveAt(0)

    ComboBox3.SelectedIndex = -1

    Button1.Visible = True
    Button2.Visible = True
    Button11.Visible = False
    Button12.Visible = False
    Button13.Visible = False
    Label4.Visible = False
    Label5.Visible = False
    Label6.Visible = False
    Label7.Visible = False
    Label8.Visible = False
    DateTimePicker1.Visible = False
    DateTimePicker2.Visible = False
    DateTimePicker3.Visible = False
    DateTimePicker4.Visible = False
    TextBox1.Visible = False

End Sub
Posted

1 solution

I have just simulated your problem...
Here, put this line below your SelectedIndex = -1 and don't worry, no item is selected.

SQL
comboBox1.SelectedIndex = -1;
comboBox1.ResetText();
 
Share this answer
 
Comments
Gary Heath 28-Jun-14 7:44am    
Brilliant, thanks goathik :-)
goathik 28-Jun-14 7:49am    
Anytime =)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900