Dear Sir/Madam,

I have used Pop Up menu to show the list_Item of a list box on Up and Down Arrow KeyPressed event. But here i can't see the list item continuously by pressing up or down keys, either i have to click/enter on that pop up menu or in the form to see the next list_item. How can we see the list item continuously by pressing up or down arrow keys. Please guide me.

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 
      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

I need some clarification...
Pop up menu show when you push up/down arrow in listbox?
What is the point of using Popup when you already see item in list?
Also Popup menu is kind-of modal form, out of focus turns visible to off

In a timer with say an interval of 1000, the following -

mnuPopup.Visible = False

I need some clarification...
Pop up menu show when you push up/down arrow in listbox?
What is the point of using Popup when you already see item in list?
Also Popup menu is kind-of modal form, out of focus turns visible to off

If my list box item is too long, and that is not visible in my list box because of list box width.

If my list box item is too long, and that is not visible in my list box because of list box width.

Then, you want to put all invisible (items out of bounds of list box) items in popup menu?

If this is point, why not put columns in list box?

Also how big will be popup window?
popup and List-box sizes are almost same size, so i do not thing that you will gain space using popup and not enlargeing listbox. Except on small forms.

commented: Very good point. +7

In a timer with say an interval of 1000, the following -

mnuPopup.Visible = False

Not working sir.

Then, you want to put all invisible (items out of bounds of list box) items in popup menu?

If this is point, why not put columns in list box?

I am not clear sir, what you have asked, for more clearance...

Suppose, i have four items in the list box as.....

1. Then, you want to
2. put all invisible
3. If this is point
4. If this is point, why not put columns in list box

Here 1 to 3 will be visible in my list box because these are 3 to 4 words long list item. But in the no. 4 list item 11 nos. of words are there. May be i can visible only 4 nos. words, not all the words in that line.

If it is a length problem, why not you use a Frame (empty captioned) with label inside (only label can not be put in front of listbox)? There is much less complications.

Then, you want to put all invisible (items out of bounds of list box) items in popup menu?

If this is point, why not put columns in list box?

Also how big will be popup window?
popup and List-box sizes are almost same size, so i do not thing that you will gain space using popup and not enlargeing listbox. Except on small forms.

Dear Sir,

I have no idea about putting culumns in list box. And popup should be long as the list item.

Actually my first choice was ToolTipText as i have asked in my previous thread. But i have not succeed on that. Please see my previous thread.

My previous thread is here

You have existing list1 and lstName. by properties that you use, I think lstName is label. If you can use that or any other label, please check following code
On every list1 item that is longer than 18 characters it will show label above list1. And hide it if length is < 18 characters.
Some of the code inside this procedure (like width. height of label) is not intend to be here but for sake of the sample i must use it this way.

Check is this works for you...

Private Sub List1_KeyUp(KeyCode As Integer, Shift As Integer)

            'lstName.Caption = List1.Text
            If Len(List1.Text) > 18 Then
                lstName.Caption = List1.Text
                lstName.Width = Len(List1.Text) * 100
                lstName.Height = 300
                lstName.BorderStyle = 1
                lstName.Left = List1.Left
                lstName.Top = List1.Top - lstName.Height
                lstName.Visible = True
                lstName.ZOrder (0)
            Else
                lstName.Visible = False
            End If
                
End Sub

Dear Sir,

Thanks for replying sir, "LstName" is the name of pop up menu. In my previous thread also some respected member suggested to use label. But my requirement is not that actually. I think i will not get the appropriate answer here. Any way, thank you once again sir.

Can you post a snap shot your UI here, just for reference.

Dear Sir,

Thanks for replying sir, "LstName" is the name of pop up menu. In my previous thread also some respected member suggested to use label. But my requirement is not that actually. I think i will not get the appropriate answer here. Any way, thank you once again sir.

giving up so easy?...

What about TextBox? If you do not like Label, use TextBox. If you make it property Flat(appearance=0) and BorderStyle=0 (none) it will look same as PopUp. Even with standar settings looks almost same as PopUp. Down you can find same code for textbox control with your measurements for position same as PopUp. Even you can select text or parts of text inside.

And if must be PopUp, there must be some specific reason. Let us hear it, maybe if this could not be solved with popup, We can try find similar control for you!

Private Sub List1_KeyUp(KeyCode As Integer, Shift As Integer)
    If Len(List1.Text) > 1 Then
        Text1.Text = List1.Text
        Text1.Width = Len(List1.Text) * 200
        Text1.Height = 400
        Text1.Left = List1.Left + List1.Width / 2
        Text1.Top = List1.Top + List1.Height / 2
        Text1.Visible = True
    Else
        Text1.Visible = False
    End If
End Sub
commented: Nice suggestion. +7
commented: I will use it sir +3

I agree with monarchmk.

I gave the suggestion on the previous posting using a popup menu. The problem here is that the popup will not change its visible property if not clicked on. The OP wants a "popup" to show when scrolling down the list, using the up/down arrow keys.

The text box control can be manipulated and used as a popup as monarch has suggested.

What I would like to know from P. Manidas, why do you need to show a popup if the user can see what text is highlighted in the list box? Maybe there is another , easier solution for you.

Also, as Das has suggested, show us a picture of your screen, maybe we will understand better of what you need. It seems we are all guessing, and it also seems that we are guessing wrong.:)

Dear Sir,

Sir, i am not going to give up for not getting solution. I am trying myself also. As per discussion with all of you sir that displaying list item in pop up menu will not be convenient for me. And we can display the list item in label or textbox or in the command button (I have done with command button).

(I have attached a test programe using these three controls)

Here, i am getting 100% solution using all these three controls. As i have mention earlier about displaying list item, my first choice is Tool Tip Text. So, i was started in my previous thread asking like "ToolTipText on pressing up or down arrow key in a ListBox".

I think that is also possible, problem is that i am not getting the idea.

I have started my previous thread because i have seen in the windows explorer of Microsoft XP that we can see the file name, type of file, date of modification and size of file as tool tip text (It may be other but it look like a tool tip text) on moving my mouse cursor to the file or pressing arrow key up or down by selecting the file.

Moreover, if the list item's length is long and some portion of that not visible then we need to show that list item some where.

As i have seen in the Windows Explorer so, i thought about tool tip text. That all the history.

Is it not possible to display list item of a list in tool tip text by pressing up or down arrow keys? (I am asking again and again, sorry for that)

Difference between tooltip, textbox or any similar text control is almoust none...
They all look almost same.
I see problem on other side. You can not control where is current(active) row in listbox and you cannot position any controls below or inline with active row.

As for tooltip VB does not have any tools that could change any property of it. And also in VB tooltips are not show if there is no mouse involved.

I have changed your code a bit. I have only used your list2 and the up/down arrow keys -

Move text1 so that list2 and text1's tops is the same.

Private Sub List2_KeyUp(KeyCode As Integer, Shift As Integer)

Text1.Visible = False
Text1.BackColor = &HD8FCFE
Text1.BorderStyle = 1

If KeyCode = vbKeyDown Then
    Text1.Visible = True
    If Len(List2.Text) >= 1 Then
        If Text1.Top >= (List1.Top + List1.Height) - (Text1.Height + 50) Then
            Text1.Top = Text1.Top
                Else
            Text1.Top = Text1.Top + 170
        End If
        Text1.Text = List2.Text
        Text1.Width = Len(List2.Text) * 150
        Text1.Left = (List2.Left + List2.Width) + 50
        Text1.Visible = True
            Else
        Text1.Visible = False
    End If
ElseIf KeyCode = vbKeyUp Then
    Text1.Visible = True
    If Len(List2.Text) >= 1 Then
        If Text1.Top >= (List1.Top + List1.Height) - (Text1.Height + 50) Then
            Text1.Top = Text1.Top - 170
        ElseIf Text1.Top <= List1.Top Then
            Text1.Top = List1.Top
                Else
            Text1.Top = Text1.Top - 170
        End If
        Text1.Text = List2.Text
        Text1.Width = Len(List2.Text) * 150
        Text1.Left = (List2.Left + List2.Width) + 50
        Text1.Visible = True
            Else
        Text1.Visible = False
    End If
End If
End Sub

This should be what you were looking for.

commented: Modification is good +3

Dear Sir,

Thank you all sir for being with me to get the result (may be not with the tooltip or pop up menu) with textbox. I am going to close this thread here. if somebody will get more information about tooltiptext please, please, please send PM to me.

AndreRet sir, your modification is looking good. Thank you sir.

And Thank you all once again.

It was only a pleasure P. Happy coding.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.