CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Location
    Canada, Quebec
    Posts
    8

    Combo box question

    In my program iam working with 2 combo box.Iam working with clear methods and the like but the problem iam facing is : If i choose a selection in the first combo box how can i decide what will be shown after in the second combo box.
    The .clear methods work ok when i need to clear but if i only want the number 10 item to the 15 one on a 1 to 100 list how can i choose to only make them shown upon as an exemple choosing option 2 on the frist combo box ? It seem i can only show allthe list or clear it completely at the moment but cant only choose some items in the list. Thanks in advance if you can help me.


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Combo box question

    Well, you could use the .Remove (index) method, but after doing that, all the other items' indexes will change. For example, if i have four items in a combo box with sequential indexes (1,2,3,4) and i remove the third item, the indexes will now be 1,2,3 even though i just removed the third one, the item with index four becomes index three. so my suggestion would be:

    Sub RemoveItems()
    'assume the combobox is named Combo1
    'get the actual text values for the items you want to remove, put them in an array.
    Dim x as integer
    Dim i as integer
    Dim theArray() as string

    for x = 0 to ubound(theArray)
    i = GetIndex(theArray(x),Combo1)
    Combo1.Remove i
    next x

    End Sub

    'this routine will go through the list and return the correct index
    public Function GetIndex(sFind as string, cboBox as ComboBox) as integer

    Dim i as Integer
    Dim intCounter as Integer

    With cboBox
    intCounter = .ListCount - 1
    for i = 0 to intCounter
    If .List(i) = sFind then
    GetIndex = k
    Exit for
    End If
    next
    End With

    End Sub




    That should get you going.

    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

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

Featured