How to catch the row change event in a datagrid?

Hi everybody,

How to catch the row change event in a datagrid I'm using VB.NET.

I have a datagrid filled from a table. I want to raise the row change event when the user selects a row.


I found the code for it in C#, but I want an example in VB.NET.


Answer this question

How to catch the row change event in a datagrid?

  • Joe Bruce

    Use the RowEnter or RowLeave event

    Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter

    End Sub

    Private Sub DataGridView1_RowLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowLeave

    End Sub


    DataGridView1 is your DataGridView name.


  • Cleverp

    You are right, it doesnt have the Row Change Event implicitly. You will most probably have to use either the CurrentCellChanged event or the Click event. There is a protected event also for row header clicks : RowHeaderClick
  • Natallica

    well, i think the datagrid in VB.NET for win app in .NET framework is a bit different. the datagrid current row change event is not there, so i have to write code to create the event myself. Anyway, thanks for the replies.

    can any one else help me with this problem  

  • Andrew Lloyd

    Thanks for the reply.

    Do you mean Datagrid by Datagridview Is it the same I tried to implement the code to my datagrid like this:
     
    Private Sub DataGrid1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid1.RowEnter

    Datagrid1 is my datagrid name.

    But it does recognise the system.Windows.Forms.DataGridViewCellEventArgs and also the .RowEnter which is at the end of code.

    I think the datagrid in win forms does have the RowEnter or RowLeave event.

    Any comment

  • dops

    Datagridview is the advanced datagrid control in VS 2005. It should work in pretty much the same way. You will have to change the event args to the appropriate type.
  • How to catch the row change event in a datagrid?