[Solved] How to scroll a Gridview via code

Post

Posted
Rating:
#1 (In Topic #1202)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
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

Code (gambas)

  1. Global.RowCount = 0
This runs when the form opens

Code (gambas)

  1. Public Sub btnUpArrow_Click()
  2.     If Global.RowCount >= 1 Then
  3.         GridViewProducts.Select((Global.RowCount - 1), 1)
  4.     End If
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


Code (gambas)

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

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
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
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…

Code (gambas)

  1.  
  2. Public Sub btnDownArrow_Click()
  3.  
  4.   GridViewProducts.Select(Min(GridViewProducts.Rows.Max, GridViewProducts.Row + 1), 1)
  5.  
  6.  
  7. Public Sub btnUpArrow_Click()
  8.  
  9.   GridViewProducts.Select(Max(0 , GridViewProducts.Row - 1), 1)
  10.  
  11.  
  12.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
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)

Code (gambas)

  1.  
  2. Global.RowPos = 0
  3.  
  4.  

Code (gambas)

  1. Public Sub btnUpArrow_Click()
  2.  
  3.   Global.RowPos = Max(Global.RowPos - 1, 0) ' reduce by one if not less that zero
  4.  
  5.   ' Select if it's a different position
  6.   If Global.RowPos <> GridViewProducts.Row Then GridViewProducts.Select((Global.RowPos), 1)
  7.  
  8.  

Code (gambas)

  1. Public Sub btnDownArrow_Click() ' same as above but incrementing position
  2.  
  3.   Global.RowPos = Min(Global.RowPos + 1, GridViewProducts.Rows.Max)
  4.   If Global.RowPos <> GridViewProducts.Row Then GridViewProducts.Select((Global.RowPos), 1)
  5.  
  6.  


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…

Code (gambas)

  1.  
  2. Global.RowPos = 0
  3.  
  4.  

Code (gambas)

  1. Public Sub btnMovePos_Click()
  2.  
  3.   Dim iNewValue as Integer = Global.RowPos + If(Last.Name = "btnDownArrow", 1, -1) ' set new position up or down 1
  4.  
  5.   Global.RowPos = Max(0, Min(iNewValue, GridViewProducts.Max)) ' make sure it is within row bounds using Max(Min()).
  6.  
  7.   ' Select if it's a different position
  8.   If Global.RowPos <> GridViewProducts.Row Then GridViewProducts.Select((Global.RowPos), 1)
  9.  
  10.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.