Results 1 to 5 of 5

Thread: [RESOLVED]ComboBox - stupid problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    [RESOLVED]ComboBox - stupid problem

    Hi All

    Just stupid problem or I have eclipse mind.

    I’ve an form 1 Combo and 1 CommandButton, I practise writing loop For...Next
    What am I doing wrong? I Want clear all items in ComboBox. I make such code.

    VB Code:
    1. Private Sub Command1_Click()
    2.     For i = 0 To Combo1.List(i)
    3.         Combo1.RemoveItem.List
    4.     Next
    5. End Sub

    And don't work, why?

    thanks for every help
    Last edited by Tamgovb; Feb 26th, 2006 at 07:15 AM.
    I know, I know, my English is bad, sorry .....

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: ComboBox - stupid problem

    Just do:

    VB Code:
    1. combo1.clear

    or if you wanted to do it your way:

    VB Code:
    1. For N = 0 To Combo1.ListCount - 1
    2.   Combo1.RemoveItem 0
    3. Next N

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: ComboBox - stupid problem

    really,........ how I could does not think about this

    Thanks very, very much
    I know, I know, my English is bad, sorry .....

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: ComboBox - stupid problem

    try this:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim i%
    3.  
    4.     For i = (Combo1.ListCount) To 1 Step -1
    5.         Combo1.RemoveItem (i - 1)
    6.     Next i
    7. End Sub
    backward loop because, when you delete 1 item, the list gets organised automatically. i.e. if you delete 3rd element, then the 4th one becomes 3rd, 5th becomes 4th and so on.

    Harsh Gupta
    Last edited by Harsh Gupta; Feb 26th, 2006 at 11:33 AM.
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: ComboBox - stupid problem

    Thanks Harsh Gupta, your code is fine, I will test this
    I know, I know, my English is bad, sorry .....

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