Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add Popup Menu...

Posted on 2004-10-11
13
Medium Priority
?
313 Views
Last Modified: 2008-02-01
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




0
Comment
Question by:Mike Eghtebas
  • 7
  • 5
13 Comments
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 1600 total points
ID: 12283963
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
 
LVL 10

Assisted Solution

by:anv
anv earned 400 total points
ID: 12284104
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12287426
Thank you all.  I will try the solutions in a day or two.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12294497
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
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12294997
>> 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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12301730
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12302077
Oops, I guess zzzzzooc have the necessary code to build the menu.  Please ignor my last post.

Mike
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12331214
What's the status on this question?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12334363
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
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12335631
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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12335713
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
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12335891
>>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
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 12340689
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question