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
Printable View
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
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
:)
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
thank you
I have another Question on listview Multiselect anyone up for it?
Its too tricky for me
If you don't post it, we can't answer it :p
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
Think the above might work...Haven't tried it in VB, but I am almost sure it will work :)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
Did it work?
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
Strange...:confused:
I'll have another look at it now...but that is how to do it, I am almost positive :)
well if it doesn't work, you should still get a few points just more making a pretty if cluster :D
Hey, that looks wierd :)
I have just viewed the pattern again, and it looks like a flying swan, how cool is that. :cool:
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...
Hey, that looks wierd :)
I have just viewed the pattern again, and it looks like a flying swan, how cool is that. :cool:
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...
wow, must have been some promotion :D
i've got a little dream of designing my own house some day. way into the future mind you though - im only 22 :)
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!
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 :D
Getting back to the thread...
You'll need
...I think.VB Code:
For Each lvwMainItem In lstMain.listitems
(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...)
Thats it!
Thanks alot
That's exactally what I put....hmmmmmmmmmmmmmm :(
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.
:confused:
thanx
That's a Type Mismatch error.
Make sure lvwMainItemW is defined as a ListItem,
and lvwDep is a ListView.