views:

3591

answers:

6

Hi,

I'm learning VB.NET.

I've a problem with DataGridView component when trying to set the value of the CurrentCell. What i'm trying to do is :

I've a DataGridView With values. I want to make a button in my forms and when clicking on it I want to change the selection from the current row to the next. To explain more, by clicking my Button I want to simulate the effect of a mouse click on a DataGridview.

I hope you can help me,

Thanks!

A: 

You need to set the particular row's Selected property to true. I think the VB would be something like this:

someDGV.Rows(index).Selected = True
Jess
A: 

You could do it this way:

If DataGridView1.CurrentRow.Index < DataGridView1.Rows.Count Then
    DataGridView1.Rows(DataGridView1.CurrentRow.Index + 1).Selected = True
End If
splattne
+4  A: 

Maybe something like this:

    If DataGridView1.RowCount > 0 Then

        Dim MyDesiredIndex As Integer = 0

        If DataGridView1.CurrentRow.Index < DataGridView1.RowCount - 1 Then
            MyDesiredIndex = DataGridView1.CurrentRow.Index + 1
        End If

        DataGridView1.ClearSelection()            
        DataGridView1.CurrentCell = DataGridView1.Rows(MyDesiredIndex).Cells(0)
        DataGridView1.Rows(MyDesiredIndex).Selected = True

    End If

Note 1: maybe these two lines are not necessary. I haven´t proved it

        DataGridView1.ClearSelection()            
        DataGridView1.CurrentCell = DataGridView1.Rows(MyDesiredIndex).Cells(0)

Note 2: note that if we are in the last row, it goes to first

Javier Morillo
A: 

Hi, Thanks for your responses. It works fine.

Tahnks.

Dali
A: 

Thank you !!! Thank you once again !!! you helped me lots of!!! Thanks once again!!!

Regards from Jay Tanna

Jay Tanna
A: 

Hi,

I'm learning VB.NET.

I've a problem with DataGridView component when trying to set the value of the CurrentCell. What i'm trying to do is :

I've a DataGridView With values. I want to make a button in my forms and when clicking on it I want to change the the entire row from the current row to the next. To explain more, by clicking my Button I want to simulate the effect of a mouse click on a DataGridview.

I hope you can help me,

Thanks!

Arun
If you want to ask a question, don't put it in an answerbut start a new thread for it.The "Ask Question" button ins in the top right of this page.More people would see your question and try to answer that way.
sth