user1532468
user1532468

Reputation: 1753

Restore Combobox to original state on form close

I have a dropdown combobox that populates dropdown combobox based on the value of the first. That works fine. However, if I select an item in the the dropdown and close the form, when I reopen, the old values are still showing in the dropdown instead of the defaults when the form is first opened. I am populating the dropdown on a from_load event and the dropdownstyle = dropdown. I would be grateful if someone could assist me with this. Many thanks

'Routine to fill customer combo box

    Sub fillClientCombo()
        DBConnection.connect()
        sql = "SELECT * from Customers"

        Dim cmd As New OleDb.OleDbCommand
        cmd.CommandText = sql
        cmd.Connection = oledbCnn
        dr = cmd.ExecuteReader

        cmbCustomer.Text = "Select a customer"
        cmbDept.Text = "Select a dept"
        cmbRequestBy.Text = "Select a contact"

        While (dr.Read())

            cmbCustomer.Items.Add(dr("Code"))

        End While

        cmd.Dispose()
        dr.Close()
        oledbCnn.Close()
    End Sub

Upvotes: 0

Views: 182

Answers (2)

It's simple, just clear the ComboBox before you populate it:

Sub fillClientCombo()
    cmbCustomer.Items.Clear()'<-- Do this first
    '...Your code
End Sub

Upvotes: 1

FoxHound
FoxHound

Reputation: 404

Add a FormClosed event to your form and clear or reset your combobox there.

Upvotes: 1

Related Questions