[Solved] Loop at top and bottom of Gridview

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Solved] Loop at top and bottom of Gridview

Post by AndyGable »

Hi All

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

Code: Select all

' 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
Last edited by AndyGable on Friday 26th August 2022 8:03am, edited 1 time in total.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Loop at top and bottom of Gridview

Post by BruceSteers »

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?...

Public Sub Form_KeyPress()

    Select Case Key.Code 
        Case Global.Key_ArrowUp
            GridView1.Select(if(GridView1.Row = 0, GridView1.Rows.Max, GridView1.Row - 1)) 
        
        Case Global.Key_ArrowDown
            GridView1.Select(if(GridView1.Row = GridView1.Rows.Max, 0, GridView1.Row + 1)) 
            
        Case Global.Key_Enter, Key.Return
            'process the selected reason
    End Select

End


If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Loop at top and bottom of Gridview

Post by AndyGable »

BruceSteers wrote: Friday 26th August 2022 3:49am 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?...

Public Sub Form_KeyPress()

    Select Case Key.Code 
        Case Global.Key_ArrowUp
            GridView1.Select(if(GridView1.Row = 0, GridView1.Rows.Max, GridView1.Row - 1)) 
        
        Case Global.Key_ArrowDown
            GridView1.Select(if(GridView1.Row = GridView1.Rows.Max, 0, GridView1.Row + 1)) 
            
        Case Global.Key_Enter, Key.Return
            'process the selected reason
    End Select

End



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 :)
Post Reply