Lets say I have a listbox.
How would I add an item to the listbox ?
Printable View
Lets say I have a listbox.
How would I add an item to the listbox ?
ListBox.Additem
I might be too asleep... but is there any help for VB? Press F1, I can assure there are example for that matter.
ur kidding right...
hmm, i think plender's pulling legs.
heh too right :)Quote:
Originally posted by darre1
ur kidding right...
hmm, i think plender's pulling legs.
ok smartypants...
why not just create and populate the listbox through a long list of API calls.
:D
or howsabout we don't reinvent the wheel ;) ?Quote:
Originally posted by darre1
ok smartypants...
why not just create and populate the listbox through a long list of API calls.
:D
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 :D
From time to time I tend to ask stupid questions just to see how people would react :)
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
:)
;)Quote:
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
:)
Fun puzzle: How do you make a listbox that has only the last two selections selected?
I didn't solve it. :(
The last two items selected you mean ?
yes - so you always keep the two (or 'n') most recent items selected
VB Code:
List1.Selected(List1.ListCount - 1) = True List1.Selected(List1.ListCount - 2) = True
I guess that's what I said...but it's not what I meant :)
And make sure MultiSelect is turned on
ha haa,
plenderj's thread just turned into something useful
:D
goddamn I hate it when that happens :)Quote:
Originally posted by darre1
ha haa,
plenderj's thread just turned into something useful
:D
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. :confused:
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
:)
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.
I think the answer to your problem regarding the listbox is:
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? :confused: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
I can define a string using:
Anyone know how do you define an Integer? ;)VB Code:
Dim strString As String
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
heh Serge, did you move my soccer thread into chit-chat ? :)
Serge, that works perfectly.
Can you explain SendMessage? I don't understand what it is doing.
Yup, I thought it belongs in the Chit-Chat area :)Quote:
Originally posted by plenderj
heh Serge, did you move my soccer thread into chit-chat ? :)
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.Quote:
Originally posted by billwagnon
Serge, that works perfectly.
Can you explain SendMessage? I don't understand what it is doing.
Well I'd like to lodge a formal complaint.Quote:
Originally posted by Serge
Yup, I thought it belongs in the Chit-Chat area :)
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 ...
;)
lol :D