Problem with menu in gridview

Post your Gambas programming questions here.
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Problem with menu in gridview

Post 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
User avatar
BruceSteers
Posts: 1587
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Problem with menu in gridview

Post 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.
If at first you don't succeed , try doing something differently.
BruceS
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Problem with menu in gridview

Post 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
User avatar
thatbruce
Posts: 170
Joined: Saturday 4th September 2021 11:29pm

Re: Problem with menu in gridview

Post by thatbruce »

[Redacted. We use a customized version of the gridview that makes all I said nonsense. Sorry!]
Last edited by thatbruce on Sunday 31st March 2024 10:58am, edited 2 times in total.
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1587
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Problem with menu in gridview

Post 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 :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 170
Joined: Saturday 4th September 2021 11:29pm

Re: Problem with menu in gridview

Post 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
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1587
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Problem with menu in gridview

Post 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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1587
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Problem with menu in gridview

Post 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?
If at first you don't succeed , try doing something differently.
BruceS
bill-lancaster
Posts: 195
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Problem with menu in gridview

Post by bill-lancaster »

Thanks Bruce,
My right button gives mouse.button = 2!
User avatar
BruceSteers
Posts: 1587
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Problem with menu in gridview

Post 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.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply