Add Popup Menu...

I have List1 on a vb 6 form.  This list box is populated with:

List1.Clear
List1.AddItem "Report1   2"
List1.AddItem "Report2   3"
List1.AddItem "Report2   1"

On mouse right-click, I want to present the user with some options to select from.

If it is clicked on Report1, the options will be
  1
  2
  3

If it is clicked on Report2, the options will be
  1
  2
  3
  4

If it is clicked on Report3, the options will be
  1
  2

And. after the selection from the popup menue, the selected number to replace the number in front of Reort?.

For example, if on Report2, option 4 is selected, the original "Report2  3" should become "Report2  4"\

Thanks




LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
zzzzzoocConnect With a Mentor Commented:
Form1:
------------------
Option Explicit
Private Sub Form_Load()
    Call List1.Clear
    Call List1.AddItem("Report1   2")
    Call List1.AddItem("Report2   3")
    Call List1.AddItem("Report3   1")
End Sub
Private Sub ShowPopup(ByVal bln1 As Boolean, ByVal bln2 As Boolean, ByVal bln3 As Boolean, ByVal bln4 As Boolean)
    'Create menus:
    'mnuPopUp
    '   mnuPopUp_ (index 1)
    '   mnuPopUp_ (index 2)
    '   mnuPopUp_ (index 3)
    '   mnuPopUp_ (index 4)
    mnuPopUp_(1).Visible = bln1
    mnuPopUp_(2).Visible = bln2
    mnuPopUp_(3).Visible = bln3
    mnuPopUp_(4).Visible = bln4
    Call Me.PopupMenu(mnuPopUp)
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim intTemp As Integer
    'If an item is selected...
    If List1.ListIndex > -1 Then
        'If right button was pressed...
        If Button = vbRightButton Then
            'Get the number of the report.. Example: Report1 .. the number is 1
            intTemp = Mid(List1.List(List1.ListIndex), 7, 1)
            Select Case intTemp
                Case 1
                    Call ShowPopup(True, True, True, False)
                Case 2
                    Call ShowPopup(True, True, True, True)
                Case 3
                    Call ShowPopup(True, True, False, False)
            End Select
        End If
    End If
End Sub
Private Sub mnuPopUp__Click(Index As Integer)
    Dim strTemp As String
    strTemp = List1.List(List1.ListIndex)
    Mid(strTemp, 11, 1) = CStr(Index)
    List1.List(List1.ListIndex) = strTemp
End Sub
0
 
anvConnect With a Mentor Commented:
u need to first create a menu..using menueditor..

set its visibility to false..

like.
MainMenu  visible = false
...1
...2
...3
...4
...5



Dim WhichRep As String

Private Sub Form_Load()
List1.Clear
List1.AddItem "Report1   2"
List1.AddItem "Report2   3"
List1.AddItem "Report2   1"
End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then
        If InStr(1, Me.List1.List(List1.ListIndex), "Report1", vbTextCompare) > 0 Then
            Me.PopupMenu mnuMain
            mnu1.Visible = True
            mnu2.Visible = True
            mnu3.Visible = True
            mnu4.Visible = False
           
            WhichRep = "Rep1"
        ElseIf InStr(1, Me.List1.List(List1.ListIndex), "Report2", vbTextCompare) > 0 Then
            WhichRep = "Rep2"
            Me.PopupMenu mnuMain
            mnu1.Visible = True
            mnu2.Visible = True
            mnu3.Visible = True
            mnu4.Visible = True
           
        ElseIf InStr(1, Me.List1.List(List1.ListIndex), "Report3", vbTextCompare) > 0 Then
             Me.PopupMenu mnuMain
            WhichRep = "Rep3"
            mnu1.Visible = True
            mnu2.Visible = True
            mnu3.Visible = False
            mnu4.Visible = False
        End If
    End If
End Sub

Private Sub mnu2_Click()
Select Case WhichRep
    Case "Rep1"
        List1.RemoveItem (List1.ListIndex)
       
        List1.AddItem "Report1   2"
    Case "Rep2"
        List1.RemoveItem (List1.ListIndex)
       
        List1.AddItem "Report2   2"
       
    Case "Rep3"
        List1.RemoveItem (List1.ListIndex)
       
        List1.AddItem "Report2   3"

   
End Select
End Sub

0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you all.  I will try the solutions in a day or two.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi  zzzzzooc,

In:  Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      .
      .          
      'Get the number of the report.. Example: Report1 .. the number is 1
            intTemp = Mid(List1.List(List1.ListIndex), 7, 1)    <-- I have following problems with this line:

1. Sometimes I have two selections (multi select list box).
2. It returns the item with dotted lines around it (selected or not)

Do you thing I can use mouse Y-Position to see what is being right-clicked on?  Meanwhile, I will try the solution from anv.

Mike


0
 
zzzzzoocCommented:
>> Do you thing I can use mouse Y-Position to see what is being right-clicked on?
The below covers that. I didn't include the menu portion since I didn't want to have to include the add menus to the project again for nothing.


Form1:
---------------
Option Explicit

Private Type POINTAPI
  X  As Long
  Y  As Long
End Type

Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function LBItemFromPt Lib "comctl32" (ByVal hLB As Long, ByVal X As Long, ByVal Y As Long, ByVal bAutoScroll As Long) As Long
Private Sub Form_Load()
    Call List1.Clear
    Call List1.AddItem("Report1   2")
    Call List1.AddItem("Report2   3")
    Call List1.AddItem("Report3   1")
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim typPoint As POINTAPI, lngSel As Long, intTemp As Integer
    If Button = vbRightButton Then
        typPoint.X = X \ Screen.TwipsPerPixelX
        typPoint.Y = Y \ Screen.TwipsPerPixelY
        Call ClientToScreen(List1.hWnd, typPoint)
        lngSel = LBItemFromPt(List1.hWnd, typPoint.X, typPoint.Y, False)
        If lngSel > -1 Then
            List1.Selected(lngSel) = True
            intTemp = Mid(List1.List(lngSel), 7, 1)
            Call MsgBox(intTemp)
        End If
    End If
End Sub
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Hi anv,

Re:> u need to first create a menu..using menueditor..

What is the code to do that?  Do you want me to post another question to handle it?

Btw, I have only three items in this list box.  So, I need only three popup menues.  And, there are no other menues (popup or other kind) available.  

Report1   2
Report2   3
Report3   1
----------
I guess, I have to use combination of the code from bothe of you.  Mainly code from avi and Y-Posiotion to figure out which of those three items is mouse at on mouse-up and mouse-down events.

Regards,

Mike
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Oops, I guess zzzzzooc have the necessary code to build the menu.  Please ignor my last post.

Mike
0
 
zzzzzoocCommented:
What's the status on this question?
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
zzzzzooc,

Your code using X-position and Y-Position works wonderfully; but I thought your previous code shows how to make (build) popup menues.  I was wrong.  I went back and fort on this question confusing everybody,  now I need code from you to make popup these popup menues before calling them.

FYI, I don't have any other menues in this application.

Regards,

Mike
0
 
zzzzzoocCommented:
The ShowPopup() procedure shows the pop-up menu(s) which you'll need to create using the Menu Editor (CTRL+E). I mentioned the general layout of the menu within that procedure.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I am getting error at:

Private Sub ShowPopup(ByVal bln1 As Boolean, ByVal bln2 As Boolean, ByVal bln3 As Boolean, ByVal bln4 As Boolean)
    'Create menus:
    'mnuPopUp
    '   mnuPopUp_ (index 1)
    '   mnuPopUp_ (index 2)
    '   mnuPopUp_ (index 3)
    '   mnuPopUp_ (index 4)
    mnuPopUp_(1).Visible = bln1            <-- sub or function not defined

In form design view, I click CTRL+E it gave me an interface to work with it.  I will try to make the menues (haven't used before).  I will get back to you later.  If the process has pitfalls, please tell me about it.

Thanks,

Mike
0
 
zzzzzoocCommented:
>>If the process has pitfalls, please tell me about it.
Remember me mentioning indexes. Assign the indexes correctly for each menu-item for my example to work correctly.
0
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
0
All Courses

From novice to tech pro — start learning today.