Problem with menu in gridview
Posted
#1
(In Topic #1218)
Regular

https://forum.gambas.o…t=959&hilit=gridview+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
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
Posted
Guru

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…
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.
Posted
Regular

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

Posted
Guru

bill-lancaster said
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…
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
Posted
Regular

Mmmyes. I was wondering about that.BruceSteers said
And If i use Menu event i get a 3 hits not just one event…
b
Posted
Guru

Posted
Guru

In your first example you use the following code…
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?
Posted
Regular

My right button gives mouse.button = 2!
Posted
Guru

bill-lancaster said
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.
Posted
Regular

b
Posted
Guru

Dang it, now i need a 2 button mouse to test with.
And I gotta think of a workaround now :-\
Best i can think of is this,,
Note the Mouse.Button value on MouseDown and then use the _Menu() event to set it.
But the _Menu event needs to fire before it's known.
Then i know if $iRightButton <> -1 then the Right (menu) button is known.
Darn i wish things were simpler
Posted
Regular

Posted
Guru

bill-lancaster said
My centre button returns mouse.button=3 and Right click gives Mouse.Right=True.
Be careful using Mouse.Left and Mouse.Right though Bill as they are more like button "down" registers than button "click".
Ie , if you press left button while right button is also held down then Mouse.Right will be true with the left click. (if that makes sense)
Aah I just discovered this could just be a QT/GTK thing.
Seems Right and Middle button value is inverted with QT5 and GTK3
With QT5 Mouse.Button = 2 for Right 3 for Middle
With GTK3 Mouse.Button = 3 for Right 2 for Middle
So the code could possibly just be like this (to ensure is correct on both toolkits)
(no idea what wayland uses)
Code (gambas)
PS. apologies Bill for slightly hijacking this thread with my outrageous need for accuracy
But i hope you have got some good stuff out of it (i know I did)
Posted
Regular

Peculiar behavior of gridview and mouse fully explored!
Bill
1 guest and 0 members have just viewed this.


