Home All Groups Group Topic Archive Search About

Stepping through datagridview rows in code

Author
21 May 2006 11:03 PM
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

Author
22 May 2006 1:07 AM
Chris
steve wrote:
Show quoteHide quote
> 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
Author
22 May 2006 3:11 AM
Walter Wang [MSFT]
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.
Author
22 May 2006 6:25 AM
steve
Hi Walter

Just what I needed

Thanks heaps

Regards
Steve

Show quoteHide quote
"Walter Wang [MSFT]" <waw***@online.microsoft.com> wrote in message
news:h3kqh1UfGHA.5992@TK2MSFTNGXA01.phx.gbl...
> 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.
>
Author
22 May 2006 6:28 AM
Cor Ligthert [MVP]
Steve.

Try to avoid for every bounded control to access it direct. Use the
currencymanager, where you than are playing with the position of that.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscurrencymanagerclasstopic.asp

I hope this helps,

Cor

Show quoteHide quote
"steve" <ga630sf@newsgroups.nospam> schreef in bericht
news:exCYRrSfGHA.3572@TK2MSFTNGP04.phx.gbl...
> 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
>