Results 1 to 4 of 4

Thread: simple array read to combobox problem

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    12

    Resolved simple array read to combobox problem

    i have an array , it stored integers "1,1,1,1,2,2,3,3,3"

    how can i write the program to use for loop to read the integer to the combobox without repeated integers?
    after read these integers to combobox, the combobox will have "1,2,3" only.

    thanks!!
    Last edited by DarkDragoon; Feb 5th, 2006 at 01:17 PM.

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: simple array read to combobox problem

    within your reading loop you can use something like..

    VB Code:
    1. if combobox1.Items.IndexOf(NewStringValue) = -1 Then ComboBox1.Items.Add(NewStringValue)

    The indexof method of any kind of item list looks for that item and returns -1 if it's not found.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    12

    Re: simple array read to combobox problem

    Quote Originally Posted by conipto
    within your reading loop you can use something like..

    VB Code:
    1. if combobox1.Items.IndexOf(NewStringValue) = -1 Then ComboBox1.Items.Add(NewStringValue)

    The indexof method of any kind of item list looks for that item and returns -1 if it's not found.

    Bill
    thanks!! it work!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: simple array read to combobox problem

    You can also use:
    VB Code:
    1. If Not myComboBox.Items.Contains(myValue) Then
    2.     myComboBox.Items.Add(myValue)
    3. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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