Results 1 to 5 of 5

Thread: ComboBox Sorting

  1. #1

    Thread Starter
    Addicted Member Appaq's Avatar
    Join Date
    Jul 2002
    Location
    Buzau | RO
    Posts
    179

    ComboBox Sorting

    Hello!

    I have a little problem sorting some names:

    combo1.additem "Writer 1"
    combo1.additem "Writer 2"
    combo1.additem "Writer 3"
    combo1.additem "Writer 4"

    Ok!
    Now begins the problem! I have a timer in my form wich i wana to make the sorting (i was thinkin'):

    Timer1.Enable = True

    If Combo1.Text = "Writer 1" then Combo2.Text = "Books of Writer 1"
    If Combo1.Text = "Writer 3" Then Combo2.Text = Books of Writer 3"



    i dont have any ideea how to write this in vb! i tried but without result! It puts me all the book in Combo2.text

    Please help me to resolve this problem!
    skin

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    I'm not 100% sure of what you are actually asking?

    What do you want to sort?

  3. #3

    Thread Starter
    Addicted Member Appaq's Avatar
    Join Date
    Jul 2002
    Location
    Buzau | RO
    Posts
    179
    ok! i dont know to speak very good english (thats one of my big problem).

    i have a form with 2 comboboxes. in first combobox i have writers" (book writers) and into the second one i have the books! But... when i select the Writer #3 then in combobox2 to show mw only the book of the writer3. Understand now ? If u dont please tell me, i`ll try to explain in other way! Btw thanx for helping me!
    skin

  4. #4

    Thread Starter
    Addicted Member Appaq's Avatar
    Join Date
    Jul 2002
    Location
    Buzau | RO
    Posts
    179
    No one can help me ? Please...
    skin

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Combo1_Click()
    4. Dim lngIndex As Long
    5.  
    6. For lngIndex = Combo2.ListCount - 1 To 0 Step -1
    7.     If Combo2.ItemData(lngIndex) <> Combo1.ItemData(Combo1.ListIndex) Then
    8.         Combo2.RemoveItem lngIndex
    9.     End If
    10. Next
    11.  
    12. End Sub
    13.  
    14.  
    15. Private Sub Form_Load()
    16. Combo1.AddItem "writer 1"
    17. Combo1.ItemData(Combo1.NewIndex) = 1
    18. Combo1.AddItem "writer 2"
    19. Combo1.ItemData(Combo1.NewIndex) = 2
    20. Combo1.AddItem "writer 3"
    21. Combo1.ItemData(Combo1.NewIndex) = 3
    22. Combo1.AddItem "writer 4"
    23. Combo1.ItemData(Combo1.NewIndex) = 4
    24.  
    25. Combo2.AddItem "book by writer2"
    26. Combo2.ItemData(Combo2.NewIndex) = 2
    27. Combo2.AddItem "another book by writer2"
    28. Combo2.ItemData(Combo2.NewIndex) = 2
    29. Combo2.AddItem "still another book by writer2"
    30. Combo2.ItemData(Combo2.NewIndex) = 2
    31. Combo2.AddItem "book by writer1"
    32. Combo2.ItemData(Combo2.NewIndex) = 1
    33. Combo2.AddItem "book by writer3"
    34. Combo2.ItemData(Combo2.NewIndex) = 3
    35.  
    36. End Sub
    You'll probably need some way to put back the deleted books.

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