views:

170

answers:

1

hi I have 2 questions:

1- We all know that can create an array list full of some employee objects and bind a datagridview to it.

but is that way have some advantages to other ways?

2- using the way above, how can we get the employee object info when a user clicks on a row of the datagridview?

thank you

+1  A: 

Binding the grid to a strongly typed object rather than something like a DataTable helps reduce the errors in your code when you need to work with the object because of the compiler checks. In order to get the strongly typed object when a user clicks on row you can use the RowEvent as shown below:

Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
        Dim Persons As List(Of Person) = CType(Me.DataGridView1.DataSource, List(Of Person))
        Dim SelectedPerson As Person = Persons(e.RowIndex)
        MsgBox(SelectedPerson.Name)
End Sub
rip
thank you very much rip
odiseh