[Solved] How to scroll a Gridview via code

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

[Solved] How to scroll a Gridview via code

Post by AndyGable »

Hi All,

I am having a Slight issue at the moment that I can not figure out how to sort

I am trying to scroll a gridview using a up and down arrow on the screen (this is a touch app)

This is what I have so far

Global.RowCount = 0

This runs when the form opens

Public Sub btnUpArrow_Click()
    If Global.RowCount >= 1 Then 
        GridViewProducts.Select((Global.RowCount - 1), 1)
    End If
End

I did the upArrow this way so as when it get to the second row and moves up it will go to 0 and then it would not go to a minus and crash


Public Sub btnDownArrow_Click()
    If Global.RowCount < GridViewProducts.Rows.Count Then
        GridViewProducts.Select((Global.RowCount + 1), 1)
    End If
End


Down works once and then it does nothing and the up does not work at all

Am i on the right tack or am i completly off point here
Last edited by AndyGable on Wednesday 20th March 2024 12:26am, edited 1 time in total.
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to scroll a Gridview via code

Post by BruceSteers »

Do you change Global.RowCount? is it a count or a position marker?
it looks like it should be the position marker

I'd not use it and just do this...


Public Sub btnDownArrow_Click()

  GridViewProducts.Select(Min(GridViewProducts.Rows.Max, GridViewProducts.Row + 1), 1)

End

Public Sub btnUpArrow_Click()

  GridViewProducts.Select(Max(0 , GridViewProducts.Row - 1), 1)

End

If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: How to scroll a Gridview via code

Post by BruceSteers »

Or if you want to use a global marker instead of the GridView.Row property id do it like this...
(i'll call the variable RowPos not RowCount as it makes more sense)


Global.RowPos = 0

Public Sub btnUpArrow_Click()

  Global.RowPos = Max(Global.RowPos - 1, 0) ' reduce by one if not less that zero

  ' Select if it's a different position
  If Global.RowPos <> GridViewProducts.Row Then GridViewProducts.Select((Global.RowPos), 1)

End

Public Sub btnDownArrow_Click() ' same as above but incrementing position

  Global.RowPos = Min(Global.RowPos + 1, GridViewProducts.Rows.Max) 
  If Global.RowPos <> GridViewProducts.Row Then GridViewProducts.Select((Global.RowPos), 1)

End



Well actually i would probably do it like this...
I would set the buttons to have a Group property , say btnMovePos and operate them both in the same function, just to save code...


Global.RowPos = 0

Public Sub btnMovePos_Click()

  Dim iNewValue as Integer = Global.RowPos + If(Last.Name = "btnDownArrow", 1, -1) ' set new position up or down 1

  Global.RowPos = Max(0, Min(iNewValue, GridViewProducts.Max)) ' make sure it is within row bounds using Max(Min()).

  ' Select if it's a different position
  If Global.RowPos <> GridViewProducts.Row Then GridViewProducts.Select((Global.RowPos), 1)

End
If at first you don't succeed , try doing something differently.
BruceS
Post Reply