|
-
Mar 4th, 2002, 05:19 AM
#1
Thread Starter
Retired VBF Adm1nistrator
Howto add an item to a listbox
Lets say I have a listbox.
How would I add an item to the listbox ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 05:21 AM
#2
-
Mar 4th, 2002, 05:22 AM
#3
Bouncy Member
ur kidding right...
hmm, i think plender's pulling legs.
-
Mar 4th, 2002, 05:26 AM
#4
Thread Starter
Retired VBF Adm1nistrator
Originally posted by darre1
ur kidding right...
hmm, i think plender's pulling legs.
heh too right
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 05:45 AM
#5
Bouncy Member
ok smartypants...
why not just create and populate the listbox through a long list of API calls.
-
Mar 4th, 2002, 06:01 AM
#6
Thread Starter
Retired VBF Adm1nistrator
Originally posted by darre1
ok smartypants...
why not just create and populate the listbox through a long list of API calls.
or howsabout we don't reinvent the wheel ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 06:58 AM
#7
Bouncy Member
yeh well, you asked a stupid question (considering) so i felt oblidged to give you a stupid answer.
of course, i can't be bothered either
-
Mar 4th, 2002, 07:02 AM
#8
Thread Starter
Retired VBF Adm1nistrator
From time to time I tend to ask stupid questions just to see how people would react
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 07:16 AM
#9
Frenzied Member
from time to time?
hmmmm
maybe its just me but i have though of all or your questions the same as i did with this one
-
Mar 4th, 2002, 07:20 AM
#10
Thread Starter
Retired VBF Adm1nistrator
Originally posted by kovan
from time to time?
hmmmm
maybe its just me but i have though of all or your questions the same as i did with this one
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 09:47 AM
#11
Hyperactive Member
Fun puzzle: How do you make a listbox that has only the last two selections selected?
I didn't solve it.
-
Mar 4th, 2002, 10:17 AM
#12
Thread Starter
Retired VBF Adm1nistrator
The last two items selected you mean ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 10:20 AM
#13
Hyperactive Member
yes - so you always keep the two (or 'n') most recent items selected
-
Mar 4th, 2002, 10:22 AM
#14
VB Code:
List1.Selected(List1.ListCount - 1) = True
List1.Selected(List1.ListCount - 2) = True
-
Mar 4th, 2002, 10:23 AM
#15
Hyperactive Member
I guess that's what I said...but it's not what I meant
-
Mar 4th, 2002, 10:23 AM
#16
Thread Starter
Retired VBF Adm1nistrator
And make sure MultiSelect is turned on
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 10:37 AM
#17
Bouncy Member
ha haa,
plenderj's thread just turned into something useful
-
Mar 4th, 2002, 10:40 AM
#18
Thread Starter
Retired VBF Adm1nistrator
Originally posted by darre1
ha haa,
plenderj's thread just turned into something useful
goddamn I hate it when that happens
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 10:44 AM
#19
Hyperactive Member
It hasn't been useful yet!
--In a listbox, how do you keep the two most recent (or n most recent) selections selected?
So if listbox items are
A
B
C
D
E
F
G
and I click on E, then D, then A,
A and D are selected but all others are deselected.
-
Mar 4th, 2002, 10:54 AM
#20
Bouncy Member
VB Code:
Private Sub List1_Click()
Dim lngCount As Long
Dim i As Long
Dim x As Long
If List1.SelCount < 2 Then Exit Sub 'no point
'find the second list item that is selected
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then lngCount = lngCount + 1
If lngCount >= 2 Then Exit For
Next i
If x >= List1.ListCount - 1 Then Exit Sub 'last item so exit
'deselect remaining items
For x = i + 1 To List1.ListCount - 1
List1.Selected(x) = False
Next x
End Sub
-
Mar 4th, 2002, 10:59 AM
#21
Hyperactive Member
I think it needs 'memory' of a sort.
Try your code -
click on A, then C, then D. D is deselected, but A should be deselected because it is the oldest.
-
Mar 4th, 2002, 11:39 AM
#22
You're nicked my old matey!
I think the answer to your problem regarding the listbox is:
VB Code:
Private Sub Command1_Click()
Dim adoRecordset As Recordset
Set adoRecordset = New Recordset
adoRecordset.AddItem "Woof and a packet of crisps please"
adoRecordset.AddItem "2nd Item in listbox"
adoRecordset.AddItem "3rd and final item"
Set adoRecordset = Nothing
End Sub
Hope this helps...Oh sod! I think I've made a mistake, think the code above maybe for a listview and not a listbox...Hmmmmm, can't remember now?
I can define a string using:
Anyone know how do you define an Integer?
-
Mar 4th, 2002, 11:52 AM
#23
Here you go:
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_SETSEL = &H185&
Private Sub List1_Click()
Static intPos1 As Integer
Static intPos2 As Integer
If List1.SelCount > 2 Then
'the reason I use API here is because I don't want the Click event
'to get fired when you say [b]List1.Selected(intPos1) = False[/b]
Call SendMessage(List1.hwnd, LB_SETSEL, False, ByVal intPos1)
intPos1 = intPos2
End If
Select Case List1.SelCount
Case 1
intPos1 = List1.ListIndex
Case 2
intPos2 = List1.ListIndex
Case Else
intPos1 = intPos2
intPos2 = List1.ListIndex
End Select
End Sub
-
Mar 4th, 2002, 11:54 AM
#24
Thread Starter
Retired VBF Adm1nistrator
heh Serge, did you move my soccer thread into chit-chat ?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 11:57 AM
#25
Hyperactive Member
Serge, that works perfectly.
Can you explain SendMessage? I don't understand what it is doing.
-
Mar 4th, 2002, 12:00 PM
#26
Originally posted by plenderj
heh Serge, did you move my soccer thread into chit-chat ?
Yup, I thought it belongs in the Chit-Chat area
-
Mar 4th, 2002, 12:03 PM
#27
Originally posted by billwagnon
Serge, that works perfectly.
Can you explain SendMessage? I don't understand what it is doing.
SendMessage API will do exactly what Selected property (it's actually being called when you use Selected property by VB). The only thing is that when you use Selected property, the Click event fires, so you might get "out out stack" error.
-
Mar 4th, 2002, 12:09 PM
#28
Thread Starter
Retired VBF Adm1nistrator
Originally posted by Serge
Yup, I thought it belongs in the Chit-Chat area
Well I'd like to lodge a formal complaint.
Jesus Christ and Soccer have everything to do with VB.
... and if you don't see that ... well I just don't know what to do at all at all ...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Mar 4th, 2002, 12:13 PM
#29
lol
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
|