Show dynamically selected row in datagridview

K

Karl Rhodes

I have a datagridview which is populated via a datatable.

What I would like to dynamically set a selected row and have that row
show up in the datagridview and not have to manually scroll to find the
selected row.

I had a look for all kind of "datagridview1.rows(i).focus" but there
doesnt seem to be anything. Can anyone help? I know this must be quite
simple to do but cant find it.
 
G

Guest

try:

me.DataGridView1.Rows.Item(x).Selected = true

where x is the row you want to select
 
K

Karl Rhodes

Thanks ewok, but i did try this.

While it selects the row ok, it doesnt bring this selected row to the
datagrid 'window'. This means if the datagrid is long and the selected
row is the last row, only the top rows are still visible. I would like
to have the datagrid automatically scroll so the selected row is
visible in the datagrid pane
 
G

gene kelley

I have a datagridview which is populated via a datatable.

What I would like to dynamically set a selected row and have that row
show up in the datagridview and not have to manually scroll to find the
selected row.

I had a look for all kind of "datagridview1.rows(i).focus" but there
doesnt seem to be anything. Can anyone help? I know this must be quite
simple to do but cant find it.


Move the row you want to select to the top and then select it:

Me.DataGridView.FirstDisplayedScrollingRowIndex = SelIndex
Me.GridView.Rows(SelIndex).Selected = True

The selected row will be the first row displayed, or, will be a
visible row if the selected row is near the end of the displayable
rows.

Gene
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top