Problem with menu in gridview

Post

Posted
Rating:
#1 (In Topic #1218)
Regular
bill-lancaster is in the usergroup ‘Regular’
I've had this problem before
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
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
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…


Code (gambas)

  1.  
  2. Public Sub gdvData_MouseUp()
  3.     Case 1
  4.       Print "click"
  5.     Case 2
  6.       Print "menu"
  7.       Menu1.Popup
  8.  
  9.  

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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
 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
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
[Redacted. We use a customized version of the gridview that makes all I said nonsense. Sorry!]

Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘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…

Code (gambas)

  1. Public Sub GridView1_MouseUp()
  2.  
  3.   If GridView1.Row = -1 Or If Not Mouse.Right Then Return
  4.  
  5.   Debug "Popup menu Row: "; GridView1.row
  6.  
  7.  
  8. Public Sub GridView1_Menu()
  9.  
  10.   If GridView1.Row = -1 Then Return
  11.   Debug GridView1.row
  12.  
  13.  
  14.  

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 :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

BruceSteers said

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

b

Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’

thatbruce said

BruceSteers said

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.

Code (gambas)

  1.  
  2. Public Sub GridView1_Menu()
  3.  
  4.   If GridView1.Row = -1 Then Return
  5.   Debug GridView1.row
  6.  
  7.  
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’
HANG on a minute!!!  I just noticed something…

In your first example you use the following code…

Code (gambas)

  1. Public Sub gdvData_MouseUp()
  2.     Case 1
  3.       Print "click"
  4.     Case 2
  5.       Print "menu"
  6.       gdvData.PopupMenu = "Menu1"
  7.  

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?
Online now: No Back to the top

Post

Posted
Rating:
#9
Regular
bill-lancaster is in the usergroup ‘Regular’
 Thanks Bruce,
My right button  gives mouse.button = 2!
Online now: No Back to the top

Post

Posted
Rating:
#10
Guru
BruceSteers is in the usergroup ‘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.
Online now: No Back to the top

Post

Posted
Rating:
#11
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Ah Grasshopper! Again you have failed to respect history. Olde tyme myce had only two buttons (there is some pre-history regarding a "one button mouse" but that can be disregarded) hence the numbering.
 :|  :twisted:  :D
b

Online now: No Back to the top

Post

Posted
Rating:
#12
Guru
BruceSteers is in the usergroup ‘Guru’
Is it the same for Mouse.State?

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.

Code (gambas)

  1.  
  2. Private $iRightButton as Integer = -1
  3. Private $iCurrentButton as Integer
  4.  
  5. Public Sub Form_MouseDown()
  6.  
  7.   $iCurrentButton = Mouse.Button  
  8.  
  9.  
  10. Public Sub Form_Menu()
  11.  
  12.   If $iRightButton = -1 Then
  13.     $iRightButton = $iCurrentButton
  14.  
  15.  
  16.  

Then i know if $iRightButton <> -1 then the Right (menu) button is known.
Darn i wish things were simpler
Online now: No Back to the top

Post

Posted
Rating:
#13
Regular
bill-lancaster is in the usergroup ‘Regular’
 My centre button returns mouse.button=3 and Right click gives Mouse.Right=True.
Online now: No Back to the top

Post

Posted
Rating:
#14
Guru
BruceSteers is in the usergroup ‘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)

  1.  
  2. Private $iRight As Integer = 2
  3. Private $iMiddle As Integer = 3
  4.  
  5. Public Sub Form_Open()
  6.  
  7.   If Component.IsLoaded("gb.gtk") Or If Component.IsLoaded("gb.gtk3") Then
  8.     $iRight = 3
  9.     $iMiddle = 2
  10.  
  11.  
  12.  
  13. Public Sub Form_MouseDown()
  14.  
  15.     Print "Click was Left"
  16.   Else If Mouse.Button = $iRight Then
  17.     Print "Click was Right"
  18.   Else If Mouse.Button = $iMiddle Then
  19.     Print "Click was Middle"
  20.  
  21.  
  22.  
  23.  

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) :)
Online now: No Back to the top

Post

Posted
Rating:
#15
Regular
bill-lancaster is in the usergroup ‘Regular’
 Not a problem Bruce.
Peculiar behavior of gridview and mouse fully explored!
Bill
Online now: No Back to the top
1 guest and 0 members have just viewed this.