Results 1 to 3 of 3

Thread: [RESOLVED] For Each Loop Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Resolved [RESOLVED] For Each Loop Problem

    I'm trying to use a For Each loop to iterate through a collection of items from a combobox and compare the value of each item in the collection to a string value to find the index of the string value in the combobox and then set another combobox's .selectedIndex to that index. But instead of comparing the two values, my code seems to be setting the value of the first item in the collection to the value of the item it is supposed to be being compared to! Help!

    If selID IsNot""Then
    comboColl = coPropID.Items()
    ForEach thisObject AsStringIn comboColl
    If thisObject = selID Then
    ind = coPropID.Items.IndexOf(selID)
    ExitFor
    EndIf
    Next thisObject
    coProp.SelectedIndex = ind
    EndIf

  2. #2
    Hyperactive Member
    Join Date
    Aug 2003
    Location
    Wigan, UK
    Posts
    291

    Re: For Each Loop Problem

    You wont need a loop for that
    VB Code:
    1. 'assuming coPropID is the combobox holding the items to be searched
    2. 'and coProp is the combobox to be selected
    3. coProp.SelectedIndex = coPropID.FindStringExact(selID)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2006
    Location
    UK
    Posts
    96

    Re: For Each Loop Problem

    Thingimijig, I think I love you!!! Thank you so much! That works a treat!

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