What is the code for double clicking a certain item in a list box. (EX: when I double click something that says "VB6" in a list box; a form pops up.)
Printable View
What is the code for double clicking a certain item in a list box. (EX: when I double click something that says "VB6" in a list box; a form pops up.)
VB Code:
Private Sub List1_DblClick() MsgBox List1.List(List1.ListIndex) End Sub
this is only giving me if I click the list box as a whole. I meant a certain item in there...
Rather than arguing given solution you should always try run it first - what Max gave you is absolutely correct: List1.List(List1.ListIndex) represents currently selected item in the list.
VB Code:
Private Sub List_Click() MsgBox List.Text End Sub
For Mr. |2eM!x (only) ;)
Quote:
Originally Posted by PaK4LyFe
:lol:
And also for |2eM!x
Quote:
Originally Posted by Pak4LyFe
but it isVB Code:
Msgbox List1.Text
It is WHAT !?
Guy asked for DBLCLICK ... NOT SINGLE ...
Well, you don't have to double click the selected item for this code to run you could have double clicked an empty area in the ListBox which I think was what he referred to.Quote:
Originally Posted by RhinoBull
The following code works though:VB Code:
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long Private Declare Function SendMessageNull _ Lib "user32.dll" Alias "SendMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Private Const LB_GETITEMHEIGHT As Long = &H1A1 Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) Static nTick As Long Static nOldIndex As Long Dim nHeight As Long Dim nItem As Long If Button = vbLeftButton Then 'calculate which item we have clicked on nHeight = SendMessageNull(List1.hwnd, LB_GETITEMHEIGHT, 0, 0) _ * Screen.TwipsPerPixelY nItem = List1.TopIndex + (Y \ nHeight) 'check if we actually clicked on an item If nItem < List1.ListCount Then If GetTickCount - nTick < 300 And nItem + 1 = nOldIndex Then 'okidoki we have double clicked an item MsgBox List1.List(nItem) End If End If nTick = GetTickCount nOldIndex = List1.ListIndex + 1 End If End Sub
Oh. I tried it. Yeah as long as the MultiSelect isn't on. :bigyello:Quote:
Originally Posted by dglienna
I always used the List(List1.ListIndex) thing.
Ok. Instead of List.text, it is List1.text
VB Code:
Private Sub List1_DblClick() MsgBox List1.text End Sub
No, that is NOT the case - if you click/dblclick on the "white" space in the listbox you won't get anything back ... only dblclicking on item will return "selected".Quote:
Originally Posted by Joacim Andersson
Oh yeah, you're right. All my code for nothing :cry:. It's the ListView you can double click anywhere.Quote:
Originally Posted by RhinoBull
That's exactly right! :wave:
im confused..what is wrong with the code i posted? besides having a single click instead of dblclick?
Nothing.Quote:
Originally Posted by |2eM!x
You changed the name of the standard listbox, although you tend to do that pretty often. I corrected it to List1.text
And didn't read the post question carefully. It's cool. We all make mistakes. ;)
Yeah, I did one earlier in this thread :)Quote:
Originally Posted by Jacob Roman
i dont do it dg, stupid MZ tools does it or whatever that program is called..i wish i could turn that dang menu off...
pisses me off so much!
NOTHING really, "besides having a single click instead of dblclick" - that was meant to be a little joke but I'm afraid you took it seriously ... :)Quote:
Originally Posted by |2eM!x
And the name of the Listbox too. Yeah take it easy |2eM!x. We were just pulling your chain. Everythings kool. ;)
Well you can name a ListBox simply List if you want to.Quote:
Originally Posted by Jacob Roman
i totally thought you were serious :blush:Quote:
Originally Posted by RhinoBull
Nah, not at this time - it's time for a little fun - 9 to 6 is when we should be serious ... :wave:
Sometimes is fun to pick on |2eM!x. But I have my limits since I'm not a total creep.
You can turn it off, but a better answer would be not to rename variables or controls unless you give them meaningful names.Quote:
Originally Posted by |2eM!x
im not gonna give it a meaningful name if im writing a 3 line code : /
I think this thread is going nowhere and we should all stop replying as it was resolved many replies back. :wave:
I agree! Let's stop. Rhino do you want to be the first that stops? If so please reply with a Yes otherwise please reply with a No. :bigyello:Quote:
Originally Posted by RhinoBull
Ok I'll stop too. Wait a minute. I'm supposed to be in bed. ZZZZZZzzzzzzzzzz
thank you all, but how do i make a form come up? Like in my program, I need a chatbox to popup and have certain information in there that i know how to do. And how do u make it so more then 1 chatbox appear with the info that I clicked on.
For example, I DblClick on an Item in the list box that says someone's IP Address. Chatbox appears up. I dblclick anohter item with an IP address also, another chatbox pops up. So far i only got 1 chatbox poping up. I cant seem to get 2,3,4,5,etc....
Hope i wasn't too confusing ....
Post the code that you are using...
Whne you dblclick on item in listbox:
VB Code:
Private Sub Friends_DblClick() MsgBox Friends.List(Friends.ListIndex) If vbOK = 1 Then Server.Show End If End Sub
I dont need a msgbox, I just need the chatbox to open up with the info I cliked in the listbox. And another chatbox, with a differnt item in the listbox.