954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ToolTipText on pressing up or down arrow key in a ListBox

Dear Sir/Madam

I am getting the list item of a listbox as ToolTipTest on mouse move event. How can I get the list item of a listbox as ToolTipTest by pressing Up or Down Arrow Key on KeyBoard. Please guide me.

How i have got the list item as ToolTipText on mouse move i have attached herewith the code for better understanding of my thread.

Private Sub Form_Load()
'List1.Sorted = True in design mode
List1.AddItem "Pankaj"
List1.AddItem "Jayanta"
List1.AddItem "Ramesh"
List1.AddItem "Jonali"
List1.AddItem "Karna"
List1.AddItem "Dilip"
List1.AddItem "Rajkumar"
List1.AddItem "Sankar"
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.ToolTipText = List1.Text
End Sub
P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
List1.ToolTipText = List1.Text
End If
End Sub
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

i'm modified andreRet code a bit ;)

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
    List1.ToolTipText = List1.List(List1.ListIndex + 1)
End If
End Sub
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

hmm..i got wrong here..

Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
    List1.ToolTipText = List1.List(List1.ListIndex + 1)
ElseIf KeyCode = vbKeyUp Then
    List1.ToolTipText = List1.List(List1.ListIndex - 1)
End If
End Sub
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

Dear AndreRet and Jx Man,

Thanks for replying but the Codes are not working. Here, i can see when i down or up arrow key and equally i have to little move my cursor over listbox then i am getting the result. And that result i am getting with my code also without using your codes. I need the result without moving the cursor. Thanks.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

ToolTipText is display at the cursor.

a better work around is to
1. use a label
2. change the caption
3. move it around as desired with controlled visibility.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Tooltiptext will only work when the mouse is over the control. That is what you have asked for, is it not?

To show the result, use a label that will "popup" where the mouse is as per Debasisdas's post, or use a messagebox.

Thanks JX for the correction (-1 or +1).:)

If KeyCode = vbKeyDown Then
    Msgbox List1.List(List1.ListIndex + 1)
ElseIf KeyCode = vbKeyUp Then
    Msgbox List1.List(List1.ListIndex - 1)
End If
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Dear Debasisdas and AndreRet,

I can see the tooltip in windows explorer by pressing down or up arrow key. As i have attached the picture of that where two tooltips are visible, one is retrieving by pressing arrow keys and other is by cursor. Here i have shown two tooltips because, in the screen shot cursor is not visible. Actually i want to show that cursor is not in the portion where my files are listed.

Anyway, i have seen in the window explorer. So, i thought it is possible to retrieve tooltip in VB 6.0 also by pressing arrow keys. Is it not possible?

Moreover i am trying to do as Debasisdas had said. And AndreRet sir, will it be convenient to show the tooltip in Msg Box, because we will have to close the Msg Box every time.

It will be good if we can see the listItem as tooltiptext by pressing Down or Up Arrow Key.

Thanks for replying sir.

Attachments New_Picture.bmp (731.85KB)
P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

Ah, a picture CAN speak a thousand words.;)

The "tooltip" there is actually a pop up menu, easy to get if you know how.

In your app, create a menu, then call the popup from there.

Do you know how to achieve this.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Dear AndreRet,

Thanks for quick reply sir, Is that pop up menu sir, I know something about pop up menu. But i have to try that. Can we show pop up menu as like as toottiptext?

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

Yes you can. I use it a lot, especially in datagrids.

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

A small tutorial -

Click on "Menu Editor" in your toolbar.
Leave "Caption" empty.
Enter "mnuPopUp" in the "Name" box
De-select "Visible". You do not want the menu to be visible until you call it.
Click on "Next" to insert another menu line.
Click on the "-->" arrow button to create the sub menu
In "Caption", add "List Name: "
Enter "lstName" in "Name" box

Click on "OK". The menu is now created.

To show the pop up where the mouse is, use the following -

Private Sub Command1_Click()

mnuList.Caption = List1.Text
PopupMenu mnuPopUp
End Sub


You can also show the popup over the listbox by adding -

Private Sub Command1_Click()

mnuList.Caption = List1.Text
PopupMenu mnuPopUp, , List1.Left, List1.Top + 150
End Sub


This is a rough sample, you need to tweak it to work for you. If you have any other questions about the popup menu, please open a new thread, I think the original question has been answered here.

Also mark this as solved, found at the bottom of this page, thanks.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

Dear AndreRet,

Thanks for your tutorial sir, I have solve 90% from that. But this 10% has halted me. I have tried a lot but all are in vain. Here i can't key down or up continuously, either i have to click/enter on that pop up menu or in the form. I want to see that list of item of list box pressing only down or up arrow key continuously as we can see in our windows explorer.

If KeyCode = vbKeyDown Then
    If List1.ListIndex = List1.ListCount - 1 Then
        List1.Selected(List1.ListIndex) = True
        LstName.Caption = List1.Text
        PopupMenu MnuPopup, , List1.Left + List1.Width / 2, List1.Top + List1.Height / 2
    ElseIf List1.ListIndex = -1 Then
        List1.Selected(List1.ListIndex + 1) = True
        LstName.Caption = List1.Text
        PopupMenu MnuPopup, , List1.Left + List1.Width / 2, List1.Top + List1.Height / 2
        List1.Selected(List1.ListIndex) = False
    Else
        List1.Selected(List1.ListIndex + 1) = True
        LstName.Caption = List1.Text
        PopupMenu MnuPopup, , List1.Left + List1.Width / 2, List1.Top + List1.Height / 2
        List1.Selected(List1.ListIndex - 1) = True
    End If
ElseIf KeyCode = vbKeyUp Then
    If List1.ListIndex = List1.TopIndex Then
        List1.Selected(List1.ListIndex) = True
        LstName.Caption = List1.Text
       PopupMenu MnuPopup, , List1.Left + List1.Width / 2, List1.Top + List1.Height / 2
    ElseIf List1.ListIndex = -1 Then
        List1.Selected(List1.ListIndex + 1) = True
        LstName.Caption = List1.Text
        PopupMenu MnuPopup, , List1.Left + List1.Width / 2, List1.Top + List1.Height / 2
        'List1.Selected(List1.ListIndex) = False 'this line not neccessary, putting only for understanding
    Else
        List1.Selected(List1.ListIndex - 1) = True
        LstName.Caption = List1.Text
        PopupMenu MnuPopup, , List1.Left + List1.Width / 2, List1.Top + List1.Height / 2
        List1.Selected(List1.ListIndex + 1) = True
    End If
End If
P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

Dear AndreRet,

This time i have done it 100% as i wanted, but with the Command Button control. Can we do it with the pop up menu sir. Please check out the attachment, how i have done it.

Attachments ListBoxToolTipText.zip (2.34KB)
P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

When this thread was started you were asking about ToolTipText but now you have ended up creating a Context Menu. They are not one and same. While ToolTipText is just informational in nature, PopupMenu serves totally different purpose.

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

Dear DebasisDas,

Still, I have not marked this thread as solve. If you have better ideas or codes please let me know that sir. I am eagerly waiting for that. Thanks for replying sir.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 


why don't you try this...

1. put a label control and keep incrementing its top position from the list top position and keep displaying ur list items.
2. put a timer pause for 5-10 sec...if no key is pressed blank the label caption.

dspnhn
Junior Poster in Training
90 posts since May 2008
Reputation Points: 20
Solved Threads: 13
 

You can use -

PopupMenu MnuPopup.Visible = False
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

As per my previous post (5 back), we have given you the solution to this question. You wanted to know about tooltiptext using down or up arrows. The popup menu sample is a new solution to what you need because tooltiptext will not work. That is why I have asked you to please CLOSE this thread and open a new one with your questions about popupmenus. I will not answer any more questions here, only on the new thread, and if this is marked as solved.:)

AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
 

why don't you try this...

1. put a label control and keep incrementing its top position from the list top position and keep displaying ur list items. 2. put a timer pause for 5-10 sec...if no key is pressed blank the label caption.

Dear Sir,

Thanks for replying sir, i have already checked with label and i have left that concept because as i know we can't use label over the listbox. Thanks.

P.manidas
Posting Whiz
304 posts since Oct 2008
Reputation Points: 53
Solved Threads: 14
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: