[Solved] Loop at top and bottom of Gridview

Post

Posted
Rating:
#1 (In Topic #893)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi All

I am currently using this code to move a blue highlighter bar in a grid

Code

' Gambas class file

    RowCount As Integer = 0
      NewRow As Integer = 1

Public Sub Form_Open()

    NoSale.LoadNoSaleReason
    
    GridView1.Select(0, 1) ' Set to the First row
   
    RowCount = GridView1.Rows.Count
    
End

Public Sub Form_KeyPress()

    Select Case Key.Code
        Case Global.Key_ArrowUp
            If NewRow <= RowCount Then
                GridView1.Select(NewRow, 1)
                NewRow -= 1
            Else
                GridView1.Select(RowCount, 1)
            Endif
        
        Case Global.Key_ArrowDown
            If NewRow <= RowCount Then
                GridView1.Select(NewRow, 1)
                NewRow += 1
            Else
                GridView1.Select(0, 1)
            Endif
            
        Case Global.Key_Enter, Key.Return
            'process the selected reason
    End Select

End


but I can not seem to capture the bottom and top of the loop correctly (the highlight line would disappear) if someone could advise how to capture this I would be most grateful
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
I'd forget that NewRow arg,  if i press down, then press up the NewRow won't be right.
And this line looks wrong for arrow-up…
 If NewRow <= RowCount Then

Maybe something like this?…

Code (gambas)

  1.  
  2. Public Sub Form_KeyPress()
  3.  
  4.     Select Case Key.Code
  5.         Case Global.Key_ArrowUp
  6.             GridView1.Select(if(GridView1.Row = 0, GridView1.Rows.Max, GridView1.Row - 1))
  7.        
  8.         Case Global.Key_ArrowDown
  9.             GridView1.Select(if(GridView1.Row = GridView1.Rows.Max, 0, GridView1.Row + 1))
  10.            
  11.         Case Global.Key_Enter, Key.Return
  12.             'process the selected reason
  13.     End Select
  14.  
  15.  
  16.  
  17.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

I'd forget that NewRow arg,  if i press down, then press up the NewRow won't be right.
And this line looks wrong for arrow-up…
 If NewRow <= RowCount Then

Maybe something like this?…

Code (gambas)

  1.  
  2. Public Sub Form_KeyPress()
  3.  
  4.     Select Case Key.Code
  5.         Case Global.Key_ArrowUp
  6.             GridView1.Select(if(GridView1.Row = 0, GridView1.Rows.Max, GridView1.Row - 1))
  7.        
  8.         Case Global.Key_ArrowDown
  9.             GridView1.Select(if(GridView1.Row = GridView1.Rows.Max, 0, GridView1.Row + 1))
  10.            
  11.         Case Global.Key_Enter, Key.Return
  12.             'process the selected reason
  13.     End Select
  14.  
  15.  
  16.  
  17.  


BruceSteers that works perfectly thank you so much and it is so simple as well. I would never had though of something like that
I am LOVING Gambas its so much easier to work with then VB.net 2008 and 2019 :)
Online now: No Back to the top
1 guest and 0 members have just viewed this.