|
-
Mar 4th, 2002, 04:18 AM
#1
Thread Starter
Lively Member
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
-
Mar 4th, 2002, 05:18 AM
#2
Bouncy Member
try this
VB Code:
Private Sub Command1_Click()
Dim li As ListItem
List1.Clear
For Each li In ListView1.ListItems
List1.AddItem li.Text
Next li
Set li = Nothing
End Sub
darrel
-
Mar 4th, 2002, 05:22 AM
#3
Fanatic Member
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
-
Mar 4th, 2002, 05:43 AM
#4
Thread Starter
Lively Member
-
Mar 4th, 2002, 11:13 AM
#5
Thread Starter
Lively Member
another Listview query
I have another Question on listview Multiselect anyone up for it?
Its too tricky for me
-
Mar 4th, 2002, 11:25 AM
#6
He's not the messiah, he's a very naughty boy!
If you don't post it, we can't answer it
-
Mar 4th, 2002, 11:33 AM
#7
Thread Starter
Lively Member
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:
Private Sub lstSub2_Click()
Dim li_items As ListItem
List1.Clear
For Each li_items In lstSub2.ListItems
If li_items.Selected Then List1.Additem lstMain.SelectedItem.Text & lstSub1.SelectedItem.Text & li_items.Text
Next li_items
Set li_items = Nothing
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
-
Mar 4th, 2002, 11:47 AM
#8
Wayheeeeyyyy! Buying a house!
VB Code:
Private Sub lstSub2_Click()
Dim lvwMainItem As ListItem
Dim lvwFirstItem As ListItem
Dim lvwSecondItem As ListItem
List1.Clear
For Each lvwMainItem In lstMain
If lvwMainItem.Selected Then
For Each lvwFirstItem In lstSub1
If lvwFirstItem.Selected Then
For Each lvwSecondItem In lstSub2
If lvwSecondItem.Selected Then
List1.AddItem lvwMainItem.Text & " " & lvwFirstItem.Text & " " lvwSecondItem.Text
End If
Next
End If
Next
End If
Next
End sub
Think the above might work...Haven't tried it in VB, but I am almost sure it will work
-
Mar 4th, 2002, 11:56 AM
#9
Woof said the 100mph wind and the rain agreed!
-
Mar 5th, 2002, 03:35 AM
#10
Thread Starter
Lively Member
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
-
Mar 5th, 2002, 03:42 AM
#11
-
Mar 5th, 2002, 05:01 AM
#12
Bouncy Member
well if it doesn't work, you should still get a few points just more making a pretty if cluster
-
Mar 5th, 2002, 05:08 AM
#13
-
Mar 5th, 2002, 05:08 AM
#14
-
Mar 5th, 2002, 06:05 AM
#15
-
Mar 5th, 2002, 06:16 AM
#16
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!
-
Mar 5th, 2002, 07:58 AM
#17
-
Mar 5th, 2002, 09:40 AM
#18
Frenzied Member
Getting back to the thread...
You'll need
VB Code:
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...)
-
Mar 5th, 2002, 11:13 AM
#19
Thread Starter
Lively Member
;-)
-
Mar 5th, 2002, 11:40 AM
#20
Bad code, bad badger!
That's exactally what I put....hmmmmmmmmmmmmmm
-
Mar 6th, 2002, 05:59 AM
#21
Thread Starter
Lively Member
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
-
Mar 6th, 2002, 06:03 AM
#22
Someone help me with this frog...oh! Go on, please!
That's a Type Mismatch error.
Make sure lvwMainItemW is defined as a ListItem,
and lvwDep is a ListView.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|