|
-
Aug 12th, 2010, 06:42 AM
#1
Thread Starter
New Member
[RESOLVED] Listbox refresh
-
Aug 12th, 2010, 07:25 AM
#2
Re: Listbox refresh
Once you remove the items,they're gone forever. If you want them back, you would have to add them again. I suggest adding them in code if you're not doing it already. Put it in a sub and you can call the sub under Case "All" and it will re-populate the listbox. Don't forget to clear it in the first step.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Aug 13th, 2010, 05:59 PM
#3
Re: Listbox refresh
Also, when you remove items from a listbox the listindex for the remaining listbox items change....something to keep in mind when hardcoding listindex numbers.
-
Aug 14th, 2010, 06:58 PM
#4
Re: Listbox refresh
Welcome aboard!
Removing several items from a list box that may have to be added back to that list box means that you have to store the removed items in an array. It gets even more complicated when more items are removed later with other events. As Hack has implied, adding those items back to the list where they were removed in some sort of hierarchical order will likely drive you bonkers.
Things can be simplified somewhat if the second list being operated on by the first one is a sorted list so that as removed items are added back, they are automatically sorted within it. Give that a try to maintain your sanity.
-
Aug 15th, 2010, 02:56 PM
#5
Thread Starter
New Member
Re: Listbox refresh
 Originally Posted by MarMan
Once you remove the items,they're gone forever. If you want them back, you would have to add them again. I suggest adding them in code if you're not doing it already. Put it in a sub and you can call the sub under Case "All" and it will re-populate the listbox. Don't forget to clear it in the first step.
I've added them in code and it's OK now.Thanks 
There is a sample:
Code:
Private Sub lstDB_Click()
Select Case lstDB.Text
Case "All"
lstCid.Clear
With lstCid
.AddItem "All"
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
End With
Case "2000"
lstCid.Clear
With lstCid
.AddItem "All"
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
End With
Case "2000 PDA/Smartphone"
lstCid.Clear
With lstCid
.AddItem "All"
End With
Case "2001"
lstCid.Clear
With lstCid
.AddItem "All"
End With
Case "2010"
lstCid.Clear
With lstCid
.AddItem "All"
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
End With
Case "2012"
lstCid.Clear
With lstCid
.AddItem "All"
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
End With
Case "3200"
lstCid.Clear
With lstCid
.AddItem "All"
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
End With
Case "PNX5230"
lstCid.Clear
With lstCid
.AddItem "All"
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
End With
Case "ODM"
lstCid.Clear
With lstCid
.AddItem "All"
End With
End Select
End Sub
Private Sub lstDB_GotFocus()
With lstDB
.AddItem "All"
.AddItem 2000
.AddItem "2000 PDA/Smartphone"
.AddItem 2001
.AddItem 2010
.AddItem 2012
.AddItem 2020
.AddItem 3150
.AddItem 3200
.AddItem 3210
.AddItem 3350
.AddItem "PNX5230"
.AddItem "AVR / DB1000"
.AddItem "ODM"
End With
End Sub
Now I've added a third listbox where I want to appear items depending of what I selected in first & second listbox.For example if I Select "All" from first listbox and "Item 1" from second listbox I want some items to appear in third listbox,if I select "All" from first listbox and "Item 2" form second listbox I want others items to appear in the third listbox.I need some advice for doing this in a simpe way.Using select case and if?

Thanks!
-
Aug 15th, 2010, 07:07 PM
#6
Re: Listbox refresh
Build a form with three list boxes. Set the MultiSelect property of the first two to 1-Simple. Then apply this code:
Code:
Private Sub Form_Load()
'Sample Data
For I = 1 To 50
List1.AddItem I
List2.AddItem Chr$(I + 32)
Next
End Sub
Private Sub List1_Click()
PopList3
End Sub
Private Sub List2_Click()
PopList3
End Sub
Public Sub PopList3()
List3.Clear
For I = 0 To List1.ListCount - 1
If List1.Selected(I) = True Then List3.AddItem List1.List(I)
Next
For I = 0 To List2.ListCount - 1
If List2.Selected(I) = True Then List3.AddItem List2.List(I)
Next
End Sub
As you select items from either of the first two, the third list box will contain all of the selected items.
-
Aug 16th, 2010, 03:59 AM
#7
Thread Starter
New Member
Re: Listbox refresh
 Originally Posted by Code Doc
Build a form with three list boxes. Set the MultiSelect property of the first two to 1-Simple. Then apply this code:
Code:
Private Sub Form_Load()
'Sample Data
For I = 1 To 50
List1.AddItem I
List2.AddItem Chr$(I + 32)
Next
End Sub
Private Sub List1_Click()
PopList3
End Sub
Private Sub List2_Click()
PopList3
End Sub
Public Sub PopList3()
List3.Clear
For I = 0 To List1.ListCount - 1
If List1.Selected(I) = True Then List3.AddItem List1.List(I)
Next
For I = 0 To List2.ListCount - 1
If List2.Selected(I) = True Then List3.AddItem List2.List(I)
Next
End Sub
As you select items from either of the first two, the third list box will contain all of the selected items.
Thanks but the third listbox should contain different items than the first & second ones,not the selected items from these.Other ideas?
-
Aug 16th, 2010, 06:40 AM
#8
Re: Listbox refresh
I guess I misread your earlier post. Here's what you said in post #5:
"Now I've added a third listbox where I want to appear items depending of what I selected in first & second list box."
That's the code that I wrote. So try again. What determines what items appear in the third list box?
-
Aug 16th, 2010, 07:33 AM
#9
Junior Member
Re: Listbox refresh
hmm,try using timer i think...
-
Aug 16th, 2010, 08:26 AM
#10
Thread Starter
New Member
Re: Listbox refresh
 Originally Posted by Code Doc
I guess I misread your earlier post. Here's what you said in post #5:
"Now I've added a third listbox where I want to appear items depending of what I selected in first & second list box."
That's the code that I wrote. So try again. What determines what items appear in the third list box? 
For example:
first listbox items:
All
Nokia
Motorola
Sony Ericsson
second listbox items:
All
Low-end
Middle-end
High-end
In the third listbox I want to appear some items based on what I choose in the first and second listboxes.
For example in third listbox should appear items:
1100
1101
others
only if Nokia is selected from first listbox and Low-end from second listbox.
This is what i mean,hope the examples are clear.
-
Aug 16th, 2010, 08:42 AM
#11
Re: Listbox refresh
Well you can put the code in s sub to fill the third listbox and call it from the click events from either list boxes:
Code:
Sub Fill3rdListBox
If lstDB.SelectedIndex > -1 And lstCid.SelectedIndex > -1 Then
Select Case lstDB.Items(lstDB.SelectedIndex)
Case "Nokia"
Select Case lstCid.Items(lstCid.SelectedIndex)
Case "Low-end"
Case "Middle-end"
Case "High-end"
End Select
End Select
End If
End Sub
You get the idea?
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Aug 16th, 2010, 09:02 AM
#12
Thread Starter
New Member
Re: Listbox refresh
 Originally Posted by MarMan
Well you can put the code in s sub to fill the third listbox and call it from the click events from either list boxes:
Code:
Sub Fill3rdListBox
If lstDB.SelectedIndex > -1 And lstCid.SelectedIndex > -1 Then
Select Case lstDB.Items(lstDB.SelectedIndex)
Case "Nokia"
Select Case lstCid.Items(lstCid.SelectedIndex)
Case "Low-end"
Case "Middle-end"
Case "High-end"
End Select
End Select
End If
End Sub
You get the idea?
Not really...

Uploaded with ImageShack.us
-
Aug 16th, 2010, 09:25 AM
#13
Re: Listbox refresh
I incorrectly posted .NET code. Modify it for VB6. Instead of lst.SelectedIndex change it to ListIndex I believe. Its been awhile since I used VB6. But its main purpose is to illustrate a concept. Apply the concept to your code and like always, pot questions.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Aug 16th, 2010, 10:04 AM
#14
Thread Starter
New Member
Re: Listbox refresh
 Originally Posted by MarMan
I incorrectly posted .NET code. Modify it for VB6. Instead of lst.SelectedIndex change it to ListIndex I believe. Its been awhile since I used VB6. But its main purpose is to illustrate a concept. Apply the concept to your code and like always, pot questions.
Modified:
Code:
Private Sub lstcid_Click()
If lstDB.ListIndex > -1 And lstCid.ListIndex > -1 Then
Select Case lstDB.List(lstDB.ListIndex)
Case "Nokia"
Select Case lstCid.List(lstCid.ListIndex)
Case "Low-end"
lstPhones.Clear
lstPhones.AddItem "1100"
lstPhones.AddItem "1101"
lstPhones.AddItem "1110"
Case "Middle-end"
lstPhones.Clear
lstPhones.AddItem "5200"
Case "High-end"
'Will be added
End Select
End Select
End If
End Sub
Thanks again,it seems to work,post rated!
If I have others questions can I post them here or I should start a new topic?
-
Aug 16th, 2010, 10:09 AM
#15
Re: Listbox refresh
Unless the new questions are explicitly extensions of the original question in this thread, you should create a new thread - it saves time and confusion for many people.
If your question for this thread has been answered to your satisfaction, please mark the thread as Resolved.
(it saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).
-
Aug 16th, 2010, 10:14 AM
#16
Thread Starter
New Member
Re: Listbox refresh
 Originally Posted by si_the_geek
Unless the new questions are explicitly extensions of the original question in this thread, you should create a new thread - it saves time and confusion for many people.
If your question for this thread has been answered to your satisfaction, please mark the thread as Resolved.
(it saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).
Done!
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
|