Stepping through datagridview rows in code

  • Thread starter Thread starter steve
  • Start date Start date
S

steve

Hi All

I have a datagridview bound to a datatable

Due to the use of touch screens I need to be able to scroll the grid in code
in response to a button click
i.e each button touch (click) will move the selection up 1 row

How do I do that


Regards
Steve
 
steve said:
Hi All

I have a datagridview bound to a datatable

Due to the use of touch screens I need to be able to scroll the grid in code
in response to a button click
i.e each button touch (click) will move the selection up 1 row

How do I do that


Regards
Steve

You need to change the current cell. I don't remember the exact code
but it'll be something like:

DataGridView.CurrentCell = DataGridView.Rows(RowIndex -1).Cells(0)

of course you need to check that it's not less than 0

Chris
 
Hi Steve,

Thank you for posting!

To simply scroll the DataGridView without changing selected rows, you can
use the property FirstDisplayedScrollRowIndex,

To change the selection while scrolling, you can first get the current
selected row's index by "DataGridView1.SelectedRows(0).Index", then you can
determine the index of next or previous row. Then use following code to
change selection:

DataGridView1.Rows(newindex).Selected = True

Though you may need to set the DataGridView's selection mode to single
selection first:

DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
DataGridView1.MultiSelect = False


If there's anything unclear, please feel free to post here.

Regards,

Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top