Link to home
Start Free TrialLog in
Avatar of SteveMudge
SteveMudge

asked on

ComboBox SelectedIndex = -1

I use several combo boxes on a win form.  After user selects 1 item in a combo i want the combo to reset or be what used to happen by setting the selected index to -1 but i get errors of object not being referenced.  How can i basically set that combo back to nothing.  BTW = nothing did not work

Thanks in advance
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Show your code please...  =)
Avatar of SteveMudge
SteveMudge

ASKER

Sure.  This is how all combos code looks with different names of coarse.

        Try
            txt_PO_Ordered_By.Text = coOrderedBy.SelectedItem.ToString
            coOrderedBy.SelectedIndex = -1
        Catch ex As Exception
            'MsgBox(String.Format("{0} -- Source {1} -- Type {2} -- {3} -- ", ex.Message, ex.Source, ex.GetType, "frmPOs.coOrderedBy_SelectedIndexChanged -- Setting Index to -1"))
        End Try

As you can see i have commented out the error so user does not get hit every time.  basically ignoring the error.  I guess maybe that is all I can do but i hope to learn a better way.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is one way that worked as well.

            If coOrderedBy.SelectedIndex >= 0 Then
                txt_PO_Ordered_By.Text = coOrderedBy.SelectedItem.ToString
                coOrderedBy.SelectedIndex = -1
            End If
Cool beans.  Same solution in a different flavor.  =)