3 Replies - 468 Views - Last Post: 05 August 2012 - 11:16 PM Rate Topic: -----

#1 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 124
  • Joined: 21-January 12

Navigation Button for ComboBox

Posted 05 August 2012 - 10:21 PM

i try to make navigation button to navigate items in my combobox, if user click that button, selected item in combo should change to next item (selection move to down), and if max count reach, the selection will back to the first item, here is my code with 3 sample items in combo :
ComboBox1.SelectedIndex += 1
            If ComboBox1.SelectedIndex > ComboBox1.Items.Count - 1 Then
                ComboBox1.SelectedIndex = 0
            End If


with that code, i got this error : Invalid Argument=Value of "3" is not valid for "SelectedIndex". Parameter name: Selected Index, that error appear when last item reach.

This post has been edited by artemix22: 05 August 2012 - 10:22 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Navigation Button for ComboBox

#2 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Navigation Button for ComboBox

Posted 05 August 2012 - 10:36 PM

You have first to check before incrementing the selected index. Something like:
If ComboBox1.SelectedIndex >= ComboBox1.Items.Count - 1 Then
       ComboBox1.SelectedIndex = 0
Else
      ComboBox1.SelectedIndex += 1
End If

Something like that will make sure you wont reach the unavailable index!

This post has been edited by smohd: 05 August 2012 - 10:36 PM

Was This Post Helpful? 1
  • +
  • -

#3 artemix22  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 124
  • Joined: 21-January 12

Re: Navigation Button for ComboBox

Posted 05 August 2012 - 11:10 PM

View Postsmohd, on 05 August 2012 - 10:36 PM, said:

You have first to check before incrementing the selected index. Something like:
If ComboBox1.SelectedIndex >= ComboBox1.Items.Count - 1 Then
       ComboBox1.SelectedIndex = 0
Else
      ComboBox1.SelectedIndex += 1
End If

Something like that will make sure you wont reach the unavailable index!


work like a charm! :bananaman:
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: Navigation Button for ComboBox

Posted 05 August 2012 - 11:16 PM

Glad we could help ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1