Gridview Scroll issue

Post your Gambas programming questions here.
Post Reply
Online
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Gridview Scroll issue

Post by cogier »

I want to display the last item(s) on a GridView display, not the first. I can do it but the values needed make no sense to me. Have a look at the attached program that demonstrates my query.

Thanks.
GridScrollProblem.tar
(4.45 MiB) Downloaded 416 times
Public Sub ButtonStart_Click()                                      'When the 'Start' Button is clicked...
Dim iCount As Integer                                               'Counter

GridView1.Rows.count = 101                                          'Amount of Rows needed
GridView1.Columns.count = 1                                         'Amount of Columns needed

For iCount = 0 To 100                                               'Count from 0 to 100
  GridView1[iCount, 0].Text = Str(iCount)                           'Add the value to a 'Cell'
Next

For iCount = 0 To 2200                                              'Count from 0 to 2200
  GridView1.Scroll(0, iCount)                                       'Move the 'Scroll Bar'
  LabelNumber.text = "GridView1.Scroll(0, " & Str(iCount) & ")"     'Display the values
  Wait                                                              'Loop through the event loop
  If iCount > 2100 Then Wait 0.25                                   'Slow things down at the end so that they can be seen
Next

Catch                                                               'If you close the program while it is busy this will stop an error

End
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Gridview Scroll issue

Post by stevedee »

I think your MagicNumber should just be replaced with the ScrollHeight, e.g.
For iCount = 0 To GridView1.ScrollHeight
...then you don't need to worry about how the scroll is scaled internally.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Gridview Scroll issue

Post by stevedee »

Also, if you change your row count to 100, you can use a simple fraction or multiplier to display any row e.g.
GridView1.Rows.count = 100                                        'Amount of Rows needed
GridView1.Columns.count = 1                                         'Amount of Columns needed

For iCount = 0 To 99                                               'Count from 0 to 100
  GridView1[iCount, 0].Text = Str(iCount)                           'Add the value to a 'Cell'
Next
Me.text = GridView1.ScrollHeight
For iCount = 0 To GridView1.ScrollHeight / 2                'to display row 50
  GridView1.Scroll(0, iCount)                                       'Move the 'Scroll Bar'
  LabelNumber.text = "GridView1.Scroll(0, " & Str(iCount) & ")"     'Display the values
  Wait                                                              'Loop through the event loop
Next
...or;
For iCount = 0 To (GridView1.ScrollHeight * 0.75)    'to display row 75

...or maybe something like;
intStopAtRow = 75
intStopAtRow = (intStopAtRow / GridView1.Rows.Count) * GridView1.ScrollHeight

For iCount = 0 To intStopAtRow
Online
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Gridview Scroll issue

Post by cogier »

Thanks SteveDee. By using GridView1.Scroll(0, GridView1.ScrollHeight) the scroll bar moves to the end of the data. I think that 'ScrollHeight' is a strange name for this thought. I changed the code in my 'problem' to the following: -
Public Sub ButtonStart_Click()                                      'When the 'Start' Button is clicked...
Dim iCount As Integer                                               'Counter

GridView1.Rows.count = 101                                          'Amount of Rows needed
GridView1.Columns.count = 1                                         'Amount of Columns needed

For iCount = 0 To 100                                               'Count from 0 to 100
  GridView1[iCount, 0].Text = Str(iCount)                           'Add the value to a 'Cell'
Next

GridView1.Scroll(0, GridView1.ScrollHeight)                         'Move the 'Scroll Bar' to the end

Catch                                                               'If you close the program while it is busy this will stop an error

End
Post Reply