Results 1 to 4 of 4

Thread: [RESOLVED] Combobox trouble

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    119

    Resolved [RESOLVED] Combobox trouble

    I have two combo boxes
    when I use this in the form load event
    one on the top gets populated ,other does not...why this is happening?And if I put the second one on the top, it get's populated,other one does not.
    Code:
     'add items to combo
            Me.Esic_combo.Items.Add("Down Town")
            Me.Esic_combo.Items.Add("Upper Road")
            Me.Esic_combo.Items.Add("Center Hall")
            Me.Esic_combo.Items.Add("Up Town")
            
            Me.Esic_combo.SelectedIndex = 0
            'select last item
            Me.Esic_combo.SelectedIndex = Me.Esic_combo.Items.Count + 1
    
    
            'add items to combo
            Me.EPF_Combo_off.Items.Add("Toronto")
            Me.EPF_Combo_off.Items.Add("London")
            Me.EPF_Combo_off.Items.Add("New Delhi")
            Me.EPF_Combo_off.Items.Add("Amstradam")
            
            Me.EPF_Combo_off.SelectedIndex = 0
            'select last item
            Me.EPF_Combo_off.SelectedIndex = Me.EPF_Combo_off.Items.Count + 1

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Combobox trouble

    Hmm, I think someone's telling porkies. Or they have this code in a Try loop with an empty Catch (a crime for which no punishment is too severe!)! This line ...

    Me.Esic_combo.SelectedIndex = Me.Esic_combo.Items.Count + 1

    ... will always raise an exception. You can't possibly select an item with an index that is higher than the number of items available. It should be Count -1
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Combobox trouble

    First change
    Code:
    Me.Esic_combo.SelectedIndex = Me.Esic_combo.Items.Count + 1
    to
    Code:
    Me.Esic_combo.SelectedIndex = Me.Esic_combo.Items.Count - 1
    This is your first issue. I can guarantee once it hits this line it breaks out because of the exception that this most definitely throws.. Therefore anything below that line will never be processed, i.e. the second combo is never populated.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2012
    Posts
    119

    Re: Combobox trouble

    dunfiddlin
    DavesChillaxin
    Thank you two for solving this issue

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