Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want that when i click on datagridview item...it should show different table in other datagridview.is it possible?....can anyone post simple code for it?
Posted
Comments
joshrduncan2012 17-Feb-14 9:13am    
I'd suggest making yourself familiar with the events of the datagridview and what they do.
Abhinav Chaudhary 17-Feb-14 9:17am    
but how i can get that events?...can you please tell me where to find these events?
_Zorro_ 17-Feb-14 10:24am    
http://lmgtfy.com/?q=datagridview+events

1 solution

VB
Private Sub DataGrid1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid1.CellClick
        If Me.DataGrid1.Rows.Count > 0 Then
            Me.DataGrid2.Item(0, 0).Value = Me.DataGrid1.CurrentCell.Value
        End If
    End Sub
 
Share this answer
 
Comments
Abhinav Chaudhary 18-Feb-14 7:49am    
Thank you sir,and how i can give links to these datagridview table items?...
sohail awr 19-Feb-14 7:31am    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ds As New DataSet
Dim i As Integer = 0
ds = selectdata("Select * from mst_members")

If ds.Tables(0).Rows.Count > 0 Then
While (i <> ds.Tables(0).Rows.Count)
Me.DataGrid1.Rows.Add()
Me.DataGrid1.Item(0, i).Value = ds.Tables(0).Rows(i).Item("account_no").ToString
Me.DataGrid1.Item(1, i).Value = ds.Tables(0).Rows(i).Item("member_name").ToString
i = i + 1
End While
End If
i = 0
ds.Clear()
End Sub

Public Function selectdata(ByVal str As String) As DataSet
If oCon.State = ConnectionState.Closed Then
oCon.Open()
End If
Dim cmd As New OleDbCommand(str, oCon)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Try
da.Fill(ds, "bpl")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
oCon.Close()
End Try
Return ds
End Function
Abhinav Chaudhary 22-Feb-14 6:16am    
Thank you sir...thanks for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900