Page 1 of 2
Problem with menu in gridview
Posted: Saturday 30th March 2024 1:49pm
by bill-lancaster
I've had this problem before
https://forum.gambas.one/viewtopic.php? ... dview+menu
Now I want to show a popup menu in response to menu button click and some other function in response to left button click.
The following code kind of works but two clicks of the menu button are required to show the popup menu.
Code: Select all
Public Sub Form_Open()
gdvData.Columns.Count = 1
gdvData.Rows.Count = 5
End
'
' Public Sub gdvData_Click()
' Print "click"
' End
'
' Public Sub gdvData_Menu()
' If Mouse.Button = 1 Then Return
' Print "menu"
' gdvData.PopupMenu = "Menu1"
'
' End
Public Sub gdvData_MouseUp()
Select Case Mouse.Button
Case 1
Print "click"
Case 2
Print "menu"
gdvData.PopupMenu = "Menu1"
End Select
End
Gambas 3.19.1
Re: Problem with menu in gridview
Posted: Saturday 30th March 2024 2:04pm
by BruceSteers
Yes the first right click will only set the Menu1 as the popup but at the time of the click the popup is not set.
On the second click the Popup is now set so will be opened.
Solution..
Do not bother to assign the Menu1 to the control in the MouseUp event, just open it...
Public Sub gdvData_MouseUp()
Select Case Mouse.Button
Case 1
Print "click"
Case 2
Print "menu"
Menu1.Popup
End Select
End
Or maybe try using your code in the
MouseDown event to set the gdvData.PopupMenu, then maybe the
MouseUp event will see the PopupMenu property.
Re: Problem with menu in gridview
Posted: Sunday 31st March 2024 9:38am
by bill-lancaster
That makes sense!
I notice that the gridview.row 'selected' property changes after the right click. I need to refer to the selected row so have to do it in the menu event.
Also the gridview_click event is only triggered when a row is left clicked. Right click is triggered anywhere in the grdiview even if there are zero rows.
Thanks again
Re: Problem with menu in gridview
Posted: Sunday 31st March 2024 9:45am
by thatbruce
[Redacted. We use a customized version of the gridview that makes all I said nonsense. Sorry!]
Re: Problem with menu in gridview
Posted: Sunday 31st March 2024 10:12am
by BruceSteers
bill-lancaster wrote: ↑Sunday 31st March 2024 9:38am
That makes sense!
I notice that the gridview.row 'selected' property changes after the right click. I need to refer to the selected row so have to do it in the menu event.
Thanks again
Gridview.Row doesn't
The Row is only "not yet" set in the MouseDown event.
In the MouseUp event the row is correct and as you would expect.
And also the Menu event fires outside the rows with GridView1.Row = -1 just like MouseUp event does. Like other bruce said you just have to check Row <> -1
And If i use Menu event i get a 3 hits not just one event...
If i use this code...
Public Sub GridView1_MouseUp()
If GridView1.Row = -1 Or If Not Mouse.Right Then Return
Debug "Popup menu Row: "; GridView1.row
End
Public Sub GridView1_Menu()
If GridView1.Row = -1 Then Return
Debug GridView1.row
End
I get all this with one right click on the third item...
Form1.GridView1_Menu.47: 2
Form1.GridView1_Menu.47: 2
Form1.GridView1_Menu.47: 2
Form1.GridView1_MouseUp.42: 2
But never mind , seems you found your own solution
Re: Problem with menu in gridview
Posted: Sunday 31st March 2024 11:08am
by thatbruce
BruceSteers wrote: ↑Sunday 31st March 2024 10:12am
And If i use Menu event i get a 3 hits not just one event...
Mmmyes. I was wondering about that.
b
Re: Problem with menu in gridview
Posted: Sunday 31st March 2024 11:12am
by BruceSteers
thatbruce wrote: ↑Sunday 31st March 2024 11:08am
BruceSteers wrote: ↑Sunday 31st March 2024 10:12am
And If i use Menu event i get a 3 hits not just one event...
Mmmyes. I was wondering about that.
b
it is odd, But it only gives one hit if you stop the event.
Public Sub GridView1_Menu()
If GridView1.Row = -1 Then Return
Debug GridView1.row
Stop Event
End
Re: Problem with menu in gridview
Posted: Sunday 31st March 2024 11:27am
by BruceSteers
HANG on a minute!!! I just noticed something...
In your first example you use the following code...
Public Sub gdvData_MouseUp()
Select Case Mouse.Button
Case 1
Print "click"
Case 2
Print "menu"
gdvData.PopupMenu = "Menu1"
End Select
End
Is that your code or did you just use the wrong number in the example?
Because on my machine Mouse.Button = 2 is middle mouse button, right button is 3 not 2
Perhaps that fixes your issue?
Re: Problem with menu in gridview
Posted: Tuesday 2nd April 2024 7:23am
by bill-lancaster
Thanks Bruce,
My right button gives mouse.button = 2!
Re: Problem with menu in gridview
Posted: Tuesday 2nd April 2024 9:52am
by BruceSteers
bill-lancaster wrote: ↑Tuesday 2nd April 2024 7:23am
Thanks Bruce,
My right button gives mouse.button = 2!
Hmm , thanks for letting me know, it means some of my software is not coded right as i assume right mouse to be Button 3 ! :-\
Something to be aware of i guess if we want portability between machines.