Bad row index

Post

Posted
Rating:
#1 (In Topic #911)
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
Hello

I have a problem that I don't know how to solve.

I use the MouseDown event to change a popupmenu.

I do something like this.

Code (gambas)

  1. Public Sub GridView1_MouseDown()  
  2.    
  3.      
  4.       ' In the following line I get the error: GridView1.Row (Bad row index)
  5.       Dim sSQL As String = "Select row1, row2 From Tabla1 Where row2 ='" & GridView1[GridView1.Row, 0].Text & "';"
  6.      
  7.       Dim resultado As Result = mG.gConn.Exec(sSQL)
  8.      
  9.       If resultado.Count < 1 Then
  10.          GridView1.PopupMenu = Popup1.Name
  11.       Else
  12.          GridView11.PopupMenu = Popup2.Name
  13.        Endif
  14.    Endif
  15.    
  16.  

But when I try to do a previous query to see if you have records and thus determine whether to put a popup menu or another, it returns the following error.

And I don't know how to do the previous consultation to change the popupmenu.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 Try something like…


Public Sub GridView1_MouseDown()   

   If GridView1.Row < 0 Then
    ' either display some message like "No row selected" or just
    Return
  End If
    
   If Mouse.Right Then …

hth
b

Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 The problem is that when I replace the MouseDown event with MouseUp everything works but the popup doesn't appear until I press the right click again. I mean, it forces me to repeat twice the right click on the row, this for the user is wrong.

but when I do the same with MouseDown, then since the click on the row has not occurred, it tells me the error, so I don't know what to do.

– Maybe if someone tells me how to get the popup menu by code maybe this is the solution. –

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#4
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Fixed.

I come from the previous version (3.12) of Gambas and in this I am new (3.15.2)

I notice that the Click() event changed to MouseDown and MouseUp but what I didn't know and it's very convenient is that now the event that occurs on the right click is now unambiguous with the Menu() event, now the right event is well separated from the left.

So it is solved thanks to the Menu() event where I detect completely clear that the user presses the right click and therefore I execute the same code and I know the clicked row and I open the appropriate popup.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
If you wish to stop an events default actions you can use the "Stop Event" instruction.

PS, you should always prefer the MouseUp event to the MouseDown one.

Using MouseUp and Mouse.Inside()  you can do the thing where if you click on something you can move the mouse away from it before letting the button go to cancel the click.

Another possibility is to NOT use the
GridView1.PopupMenu = Popup1.Name
instead leave the PopupMenu blank so it does not try to do anything and use the command Popup1.Popup() or Popup2.Popup() instead. That way you are in control of the action.

like…

Code (gambas)

  1.       If resultado.Count < 1 Then
  2.          Popup1.Popup(Mouse.ScreenX, Mouse.ScreenY)
  3.       Else
  4.          Popup2.Popup(Mouse.ScreenX, Mouse.ScreenY)
  5.        Endif
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#6
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
Thank you very much :)

Although I have solved it I believe well. You give me very interesting information to renew my code and update my knowledge.

Thank you, you are really very kind. Some day I will help you in your code, but it may not happen, since I suppose you are a better Gambas developer than me.

Greetings.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

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

gambafeliz said

Thank you very much :)

Although I have solved it I believe well. You give me very interesting information to renew my code and update my knowledge.

Thank you, you are really very kind. Some day I will help you in your code, but it may not happen, since I suppose you are a better Gambas developer than me.

Greetings.

All roads lead to Rome they say :)

Just a note for the Menu event (that is also a good solution:) )
If you do not want the menu to pop up if nothing is selected (this will happen if right click not on a list item) then do the following..

Code (gambas)

  1.  
  2. Public Sub GridView1_Menu()  
  3.    
  4.   If GridView1.Row = -1 Then
  5.     Stop Event  ' cancel the popup event
  6.     Return
  7.  
  8.       ' In the following line I get the error: GridView1.Row (Bad row index)
  9.       Dim sSQL As String = "Select row1, row2 From Tabla1 Where row2 ='" & GridView1[GridView1.Row, 0].Text & "';"
  10.        
  11.       Dim resultado As Result = mG.gConn.Exec(sSQL)
  12.        
  13.       If resultado.Count < 1 Then
  14.          GridView1.PopupMenu = "Popup1"
  15.       Else
  16.          GridView11.PopupMenu = "Popup2"
  17.        Endif
  18.    
  19.  

Happy coding :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.