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
Private Sub List1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
List1.ToolTipText = List1.Text
End If
End Sub

Edited 5 Years Ago by AndreRet: n/a

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

Edited 5 Years Ago by Jx_Man: n/a

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

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.

Edited 5 Years Ago by P.manidas: n/a

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.

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

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.

Edited 5 Years Ago by P.manidas: n/a

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.

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?

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.:)

Edited 5 Years Ago by AndreRet: n/a

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

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.

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.

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.

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.:)

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.

I am going to close this thread here, because, it has solved using Command Button control as per my requirement but not with the tooltiptext or popup menu.

I am going to open a new thread regarding popup menu as per suggestion of AndreRet.

This question has already been answered. Start a new discussion instead.