Results 1 to 11 of 11

Thread: Selecting Items in List Box control programmatically...

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Madras, India
    Posts
    6

    Selecting Items in List Box control programmatically...

    Hi ,

    I have created list box with the property Multiselect= 2-extended.
    I thought I can select more than one Item in the list box programmaticaly using the following code, but it is not working.

    For i= 2 to SelctedVal

    retval = SendMessage(lstNotLinked.hWnd, LB_SETSEL,
    ByVal CLng(1), ByVal CLng(i))

    Next i


    Can some body please tell me whether it is possible OR not.

    Since I am new to VB, I am not very sure of VB 6.0 capabilities.


    If any of you know how to select the list box items (more than one) programmatically then please let me know.

    Thank You very much........
    -SESH

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Is there any particular reason you are using API, as this will do
    VB Code:
    1. For i = 0 To List1.ListCount - 1 Step 2 'select every other element
    2.     List1.Selected(i) = True
    3. Next i

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Madras, India
    Posts
    6

    Selecting Items in List Box control programmatically...

    The foloowing code just select the item, but the items do not get hilighted in the list box. i.e I wanted to see those selcetd Items (List1.Selected(i) = True) as hilighted in the list box.

    For i = 0 To List1.ListCount - 1 Step 2 'select every other element
    List1.Selected(i) = True
    Next i

    Thank you...
    SESHU
    -SESH

  4. #4
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    It does highlight them, provided MultiSelect is set to Simple or Extended

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Madras, India
    Posts
    6
    It is Multiselect is Extended
    -SESH

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Madras, India
    Posts
    6
    But, I am doing it in on click event of the same list box , does it causes any problem?

    Thanks
    -SESH

  7. #7
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923

  8. #8
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Originally posted by bs2527
    But, I am doing it in on click event of the same list box , does it causes any problem?
    No that doesn't appear to cause a problem

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Madras, India
    Posts
    6
    Here is my problem,

    I have list box with few items, If user selects one Item say 1,
    then the program will automatically selects 4,5 & 6(Hilights). The selection logic for 4,5 &6 I kept in the on click event for 1, but

    It is not working...


    Hope you understand my problem...
    -SESH

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Madras, India
    Posts
    6
    I have tried that also, but no luck!!!!!!

    Is there any way to do it by generating the event for Shift key + selection , programmatically..

    Thanks for your help.
    -SESH

  11. #11
    PowerPoster beachbum's Avatar
    Join Date
    Jul 2001
    Location
    Wollongong, NSW, Australia
    Posts
    2,274
    What do you mean no luck? The code works fine for me. U have set the MultiSelect property to 1 havent u?
    what exactly is not working?
    Regards
    Stuart
    Stuart Laidlaw
    Brightspark Financial Software
    http://www.gstsmartbook.com

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