Dim cn As New SqlConnection()
Dim da As New SqlDataAdapter()
Dim dt As New DataTable()
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.ConnectionString = "user id=sa;password=password;initial catalog=pubs;"
cn.Open()
da.SelectCommand = New SqlCommand("select * from authors", cn)
da.Fill(dt)
DataGrid1.DataSource = dt
End Sub
Public Structure authors
Dim id, lname, fname, phone, address, city, state, zip, contract As String
End Structure
Dim s As authors
Public ReadOnly Property selecteditems() As authors
Get
Return s
End Get
End Property
Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
s.id = dt.Rows(DataGrid1.CurrentCell.RowNumber)(0)
s.lname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(1)
s.fname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(2)
s.phone = dt.Rows(DataGrid1.CurrentCell.RowNumber)(3)
s.address = dt.Rows(DataGrid1.CurrentCell.RowNumber)(4)
s.city = dt.Rows(DataGrid1.CurrentCell.RowNumber)(5)
s.state = dt.Rows(DataGrid1.CurrentCell.RowNumber)(6)
s.zip = dt.Rows(DataGrid1.CurrentCell.RowNumber)(7)
s.contract = dt.Rows(DataGrid1.CurrentCell.RowNumber)(8)
Close()
End Sub