Reputation: 540
I have a TreeView with a Click-Event. Since I need to implement a node-oriented dropdown-context-menu by right-click, how may I check in the existing Click-Event if the right mouse-butten was pressed. My Methode so far, looks like this:
Private Sub tvwKategorien_NodeClick(ByVal Node As Object)
Dim sBez1 As String
Dim sLangtext As String
Dim sWKZ As String
Dim sSprache As String
Dim dPreis As Double
If ((Node Is Nothing) = False) Then
If mbParseNodeKeyAndTag(Node) Then
Set moSelectedNode = Node
If msKategorie = frmArtikelgruppenRoot Then
Me.pagKategorie.Visible = False
Me.pagArtikel.Visible = False
Me.pagPicture.Visible = False
Me.pagCrosslinks.Visible = False
Me.SubArtikel.Visible = False
Me.txtKategorie = msKategorie
Me.txtBezeichnung = msBezeichnung
Me.PicArtikel.Visible = False
Call mEnableSubArtikel
Else
If mbIstNodeKategorie(moSelectedNode) Then
Me.pagKategorie.Visible = True
Me.pagArtikel.Visible = False
Me.pagPicture.Visible = False
Me.pagCrosslinks.Visible = False
Me.SubArtikel.Visible = True
Me.txtKategorie = msKategorie
Me.txtBezeichnung = msBezeichnung
Me.PicArtikel.Visible = False
If Node.Child Is Nothing Then
Dim oNodeParam As Node
Set oNodeParam = Node
Call mReadUntergruppen(oNodeParam, oNodeParam.Key, gnCInt(gsParameter(oNodeParam.Text, "Gruppenebene")) + 1)
End If
Call mEnableSubArtikel
Dim rs As Recordset
Set rs = Me.SubArtikel.Form.Recordset
If Not rs Is Nothing Then
Call mReadArtikel(Node, Node.Key, gnCInt(gsParameter(Node.Text, "Gruppenebene")) + 1)
Node.Expanded = True
Else
Node.Expanded = False
End If
Else
Me.pagKategorie.Visible = False
Me.pagArtikel.Visible = True
Me.pagPicture.Visible = True
Me.pagCrosslinks.Visible = True
Me.SubArtikel.Visible = False
Me.txtArtNr = msBezeichnung
Me.txtArt = msBezeichnung & " " & gvntLookup("Matchcode", "KHKArtikel", "Artikelnummer='" & msBezeichnung & "' AND Mandant=" & gnManId, "")
cbBild.Value = "ITPWeb_"
Call mInitPicture
nil = gITPWebGetArtPreis(msBezeichnung, 0, sWKZ, dPreis, cbShop.Value)
Me.txtArtPreis = dPreis
Me.txtArtWkz = sWKZ
If gvntNull2Arg(cboSprache, "") = "" Then
sSprache = "W" & gvntManProperty(22)
Else
sSprache = CStr(cboSprache)
End If
nil = gITPWebGetArtBez(sSprache, msBezeichnung, sBez1, sLangtext)
Me.txtArtBezeichnung = sBez1
Me.txtArtLangtext = sLangtext
msAktuelleKategorie = Split(Node.Key, ";")(0)
Me.cboBonusprodukt.Locked = False
sSplit = Split(Node.Key, ";")
Me.cboBonusprodukt.Value = gvntLookup("BonusProduct", "ITPWebKategorienArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId & " and Kategorie = " & gsStr2Sql(msAktuelleKategorie) & " and Pos = " & sSplit(getArrayLenght(sSplit)), 0)
Me.cboBonusprodukt.AllowValueListEdits = False
Me.txtBonuspunkte = gvntNull2Arg(gvntLookup("Bonuspunkte", "ITPWebKategorienArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId & " and Kategorie = " & gsStr2Sql(msAktuelleKategorie) & " and Pos = " & sSplit(getArrayLenght(sSplit)), 0), 0)
Me.chkOrderable = gvntLookup("USER_ITPWebOrderable", "KHKArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId, -1)
Me.chkShopActive = gvntLookup("USER_ITPWebShopActive", "KHKArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId, -1)
Me.chkPricePush = gvntLookup("USER_ITPWebPricePush", "KHKArtikel", "Artikelnummer=" & gsStr2Sql(msBezeichnung) & " AND Mandant=" & gnManId, 0)
Call mEnableSubCrosslinks
End If
End If
End If
End If
tvwKategorien_NodeClick_Error:
End Sub
I'm working inside an access-document with VBA :(
Upvotes: 0
Views: 2056
Reputation: 3031
You have to use MouseDown
event for your tree tvwKategorien
and flag some module variable in order to check later it in NodeClick
put this at the beginning of the Module but after Option
strings
private MouseButton as Integer
Add MouseDown
event
Private Sub tvwKategorien_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
MouseButton =Button
End Sub
Then use such condition to detect right click in your existing NodeClick
event
If MouseButton = acRightButton Then ' right
and
If MouseButton = acLeftButton Then ' left
Upvotes: 1