Results 1 to 22 of 22

Thread: Listview Multiselect Again

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Question Listview Multiselect Again

    I have 1 listview control and 1 ordinary listbox - I need to populate the ordinary listbox with only those that are selected in the listview.

    thanks

  2. #2
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    try this

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim li As ListItem
    3.    
    4.     List1.Clear
    5.     For Each li In ListView1.ListItems
    6.         List1.AddItem li.Text
    7.     Next li
    8.    
    9.     Set li = Nothing
    10. End Sub

    darrel

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  3. #3
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    The code that Darre1 posted will add all items to the listbox, try this instead to only add selected items.


    Private Sub Command1_Click()
    Dim li As ListItem

    List1.Clear
    For Each li In ListView1.ListItems
    If li.Selected Then List1.AddItem li.Text
    Next li

    Set li = Nothing
    End Sub
    Leather Face is comin...


    MCSD

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    :-)

    thank you

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Question another Listview query

    I have another Question on listview Multiselect anyone up for it?
    Its too tricky for me

  6. #6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Question Sounds Promising....

    ok......
    I have 3 listview controls named lstMain, lstSub1 and lstSub2 and a normal list box.
    Each listview control is populated with approx 200 entries (data from database) – all entries are 3 digit numbers. (data type Long)

    I have the following code that populates the list1 control with all the selected entries.

    VB Code:
    1. Private Sub lstSub2_Click()
    2.  
    3. Dim li_items As ListItem
    4.         List1.Clear
    5.  
    6. For Each li_items  In lstSub2.ListItems
    7.  
    8. If li_items.Selected Then List1.Additem lstMain.SelectedItem.Text & lstSub1.SelectedItem.Text & li_items.Text
    9.  
    10. Next li_items
    11.        
    12. Set li_items = Nothing
    13.  
    14. End sub

    The above works fine – but I now have to allow for multiple selections in ALL listview boxes.

    For example:

    LstMain may have 2 items selected
    LstSub1 may also have 2 items selected and
    LstSub2 may have 3 items selected.

    Therefore I will need a few loops to iterate through each of the boxes. I’m not sure how to do it.

    Example:

    LstMain (items 2 and 9 are selected)
    LstSub1 (items 3 and 4 are selected)
    LstSub2 (items 3, 4 and 5 are selected)
    So the data in List1 should be as follows:

    Results in the List1:
    LstMain(item 2) & LstSub1(item 3) & LstSub2(item3)
    LstMain(item 2) & LstSub1(item 3) & LstSub2(item4)
    LstMain(item 2) & LstSub1(item 3) & LstSub2(item5)
    LstMain(item 2) & LstSub1(item 4) & LstSub2(item3)
    LstMain(item 2) & LstSub1(item 4) & LstSub2(item4)
    LstMain(item 2) & LstSub1(item 4) & LstSub2(item5)

    LstMain(item 9) & LstSub1(item 3) & LstSub2(item3)
    LstMain(item 9) & LstSub1(item 3) & LstSub2(item4)
    LstMain(item 9) & LstSub1(item 3) & LstSub2(item5)
    LstMain(item 9) & LstSub1(item 4) & LstSub2(item3)
    LstMain(item 9) & LstSub1(item 4) & LstSub2(item4)
    LstMain(item 9) & LstSub1(item 4) & LstSub2(item5)

    Please respond if I’ve not explained it well enough.

    Thanx

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Wayheeeeyyyy! Buying a house!

    VB Code:
    1. Private Sub lstSub2_Click()
    2. Dim lvwMainItem As ListItem
    3. Dim lvwFirstItem As ListItem
    4. Dim lvwSecondItem As ListItem        
    5.    List1.Clear
    6.    For Each lvwMainItem In lstMain
    7.       If lvwMainItem.Selected Then
    8.          For Each lvwFirstItem In lstSub1
    9.               If lvwFirstItem.Selected Then
    10.                  For Each lvwSecondItem In lstSub2
    11.                     If lvwSecondItem.Selected Then
    12.                        List1.AddItem lvwMainItem.Text & " " & lvwFirstItem.Text & " " lvwSecondItem.Text
    13.                     End If
    14.                  Next
    15.              End If
    16.          Next
    17.       End If  
    18.    Next
    19. End sub
    Think the above might work...Haven't tried it in VB, but I am almost sure it will work

  9. #9

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Unhappy errrmm...No

    Error msg: Object doesnt support this Property or method:
    Run-Time Error 438

    When i debug i noticed it stops on the following line.
    For Each lvwMainItem In lstMain.

    I dont particularly want to use another version of this control as it may create too much work.

    thanx

  11. #11

  12. #12
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    well if it doesn't work, you should still get a few points just more making a pretty if cluster
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  13. #13
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    By the way, do you have any Squishies?

    Hey, that looks wierd
    I have just viewed the pattern again, and it looks like a flying swan, how cool is that.

    Having a crappy day, huge DLL with Huge OCX with Huge UI
    Almost got them all working together...*sigh* Once it's doen it will be VERY easy to maintain and update, it's just getting there 1st...

  14. #14
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    By the way, do you have any Squishies?

    Hey, that looks wierd
    I have just viewed the pattern again, and it looks like a flying swan, how cool is that.

    Having a crappy day, huge DLL with Huge OCX with Huge UI
    Almost got them all working together...*sigh* Once it's doen it will be VERY easy to maintain and update, it's just getting there 1st...
    Oh, and just put in an offer for a Grade 2 Listed cottage 65k, they will tell me at the weekend if I have got it...

  15. #15
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    wow, must have been some promotion

    i've got a little dream of designing my own house some day. way into the future mind you though - im only 22
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  16. #16
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    She's dead! Who will be next...Bet, Bet, Bet

    I am 26 and after failing a 5 year Electronic Eng Uni degree at Sheffield I was well stuck. I have worked hard to learn almost every aspect of VB, which gets used in the business environment and I always said that after 2 years I will be on more than 20k. After 20 months I have managed that, and very easily too Within 2 years I will be on 35K+, plus if I do this house up that I am hoping to buy then I will make around 30k on the sale of that.
    Things are just starting to go right....at last

    I don't even own a comp at home That's how much I hate them. Take your typical comp programmer, and I am at the other end of the scale, clubbing, drugs (Hmmmmm Alcohol is a drug ), drink, women, travelling, karate, football and many other sports...blah, blah, blah. most of that is going to have to stop since I am supposed to be a responsible adult moving into a country cottage *sigh* Still in University mode....

    Right you VB programmers! Why when EVER I try and edit a post, or reply to someone private messge does the PHP page set to nack?! All I get is a THIS PAGE CANNOT BE DISPLAYED message!!! EVERY TIME!, well, 95% of the time *sigh* I hate working with computers!

  17. #17
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    well i messed up at school and college (had a lot of issues that took up a lot of my time (teenagers - pah!) and then i decided to pull me act together, now i'm doing ok!

    i'm kinda in the middle though, love computers, but also love football, gym and especially music - listening to it, playing it, whatever
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  18. #18
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Getting back to the thread...
    You'll need
    VB Code:
    1. For Each lvwMainItem In lstMain.listitems
    ...I think.

    (My life story can wait for another day - it's too dull, but suffice it to say I'm not a stereotypical nerd: I don't like computers for the sake of computers but I do like making them do something useful...)

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Thumbs up ;-)

    Thats it!

    Thanks alot

  20. #20

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Posts
    116

    Unhappy Im Confused now...

    All the above examples were implimented into my ocx control and worked fine....

    I have added this control with another group of controls (no change in the code OR Data) and am now getting a runtime error 13 and this line:

    For Each lvwMainItemW In lvwDep.ListItems

    Why is this?

    It dosnt happen when its in the original project.



    thanx

  22. #22

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