locked
passing a selected row of DGV to another form (textboxes) RRS feed

  • Question

  • Hello EXPERTS,

    I hav a datagridview,which looks like this:

    ID        NAME        MARKS        GRADE
    1           SHEENA      60               C
    2           MARIA         80               B
    3           ROBBY         65               C
    4           TONY           75               B

    if i doubleclick a row,lets say highlited row...then this row value should appear to another form which hav 4 textboxes ( id , name, marks and grade)...i am a beginner so really dont hav any idea....please help me with proper code....thanx in advance...




    WIth REgards, Alizee Hayek
    Sunday, March 8, 2009 1:53 AM

Answers

  • Ok, DoubleClick Event might be good for you

     Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
            If Not DataGridView1.CurrentRow Is Nothing Then
                DataGridView1.EndEdit()
                Dim frm2 As New Form2
                frm2.TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString
                frm2.ShowDialog()
            End If
        End Sub

    Arjun Paudel
    • Marked as answer by Hayek Sunday, March 8, 2009 10:02 AM
    Sunday, March 8, 2009 3:53 AM

All replies

  • Ok, DoubleClick Event might be good for you

     Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
            If Not DataGridView1.CurrentRow Is Nothing Then
                DataGridView1.EndEdit()
                Dim frm2 As New Form2
                frm2.TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString
                frm2.ShowDialog()
            End If
        End Sub

    Arjun Paudel
    • Marked as answer by Hayek Sunday, March 8, 2009 10:02 AM
    Sunday, March 8, 2009 3:53 AM
  • hi,  ARJUN PAUDEL  

                      Thank you very much dear....now i can do it by ur code...!!!!!!!!!    Exactly this type of detail n complete guidens is expected by  every  biginner.....dear i hav one more problem regarding DGV...i started thread but still no solution...

    i have a table in sqlserver2005 which has currently following data...

    CUST_ID
           PAYMENT_NO          DUE_DATE           STATUS
      1                        1                            15.02.09               PAID
      1                        2                            15.03.09               NOTPAID  
      1                        3                            15.04.09               NOTPAID

      2                        1                            20.02.09               PAID
      2                        2                            20.03.09               NOTPAID

      3                        1                            25.02.09               NOTPAID
      3                        2                            25.03.09               NOTPAID

            Now i want to show highligted rows in a DGV according to there status, i mean show only rows of each cust_id "notpaid" status...the 1st "notpaid" status. like in cust_id 1, first "notpaid" row. I think now u got the idea wht exactly i m trying...please guide me...


                       
                      Hav a wonderful day ahead...
    WIth REgards, Alizee Hayek
    Sunday, March 8, 2009 10:07 AM