Problem with gridview menu click

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

Problem with gridview menu click

Post by bill-lancaster »

If I click left on a gridviw cell the _Click() event is triggered
If I right click (menu) on a gridview cell both the _Click() and the _Menu() events are fired.
How can I intercept just the right click?
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Problem with gridview menu click

Post by stevedee »

bill-lancaster wrote: Saturday 5th December 2020 12:02pm ...If I right click (menu) on a gridview cell both the _Click() and the _Menu() events are fired...


OK, I get it now.

I added this logic to my test code to get around the problem:-
Public Sub GridView1_Menu()   'Right mouse button

  blnMenu = True

End

Public Sub GridView1_Click() 'Left mouse button

  If blnMenu Then
    ListBox1.Add("Right_Click")
    blnMenu = False
  Else
    ListBox1.Add("Left_Click")
  Endif

End
Last edited by stevedee on Saturday 5th December 2020 5:12pm, edited 1 time in total.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Problem with gridview menu click

Post by cogier »

Hi Bill,

I have carried out some tests and you are correct both events are triggered. As the 'Click' event is not classed as a mouse event you can't check the mouse buttons. I discovered that the 'Menu' event is triggered first so knowing that I was able to set up a trap for it.

Image
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Problem with gridview menu click

Post by vuott »

I suggest this simplex exemplum:
Public Sub Form_Open()

  With GridView1
    .Columns.Count = 10
    .Rows.Count = 25
  End With

End

Public Sub GridView1_MouseUp()

  Select Case Mouse.Button
    Case 1
      GridView1[GridView1.Row, GridView1.Column].Text = "Left Click"
    Case 2
      GridView1[GridView1.Row, GridView1.Column].Text = "Right Click"
  End Select
  
  GridView1.Columns[GridView1.Column].Width = -1

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Problem with gridview menu click

Post by vuott »

bill-lancaster wrote: Saturday 5th December 2020 12:02pm How can I intercept just the right click?
Public Sub GridView1_MouseUp()

   If Mouse.Right Then
     GridView1[GridView1.Row, GridView1.Column].Text = "Right Click"
     GridView1.Columns[GridView1.Column].Width = -1
   Endif

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Problem with gridview menu click

Post by stevedee »

Yep, I think your MouseUp, Mouse.Right solution is the best vuott.

One thing that puzzles me with my test program, is that a 'right click' on the GridView results in the following event sequence:-
GridView_Menu
Form_Menu
GridView_Menu
Form_Menu
GridView_Menu
Form_Menu
GridView_Click
GridView_MouseUp
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Problem with gridview menu click

Post by bill-lancaster »

Thanks for all your help, the MouseUp, Mouse.Right solution works fine.
Post Reply