Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i get the values of a selected rows of a datagrid when i press [RETURN KEY] & dispaly it to textboxes...

please help...
here's my code...

VB
Private Sub dtgView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtgView.KeyDown
        If e.KeyCode = Keys.Enter Then
            Try
                Dim a As Integer = 0
                If dtgView.SelectedRows.Count > 0 Then
                    txtIL_ID.Text = dtgView.Item(1, a).Value
                    txtIL_Name.Text = dtgView.Item(3, a).Value
                    txtIL_Desc.Text = dtgView.Item(4, a).Value
                    txtIL_Catgry.Text = dtgView.Item(6, a).Value
                    txtIL_Packaging.Text = dtgView.Item(8, a).Value
                    txtIL_UnitCost.Text = dtgView.Item(15, a).Value
                    txtIL_WE.Text = dtgView.Item(9, a).Value
                    txtIL_RE.Text = dtgView.Item(10, a).Value
                    txtIL_WA.Text = dtgView.Item(11, a).Value
                    txtIL_OG.Text = dtgView.Item(12, a).Value
                    txtIL_QTY.Text = dtgView.Item(13, a).Value
                    'txtIL_Supp_ID.Text = dtgView.Item(0, a).Value
                    txtIL_ID.Select()
                    Me.Close()
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub


please help me...
thanks in advanced...
Posted

This article Editable GridView in ASP.NET 2.0 and this article Accessing the different controls inside a GridView control should answer your question. They are very good articles, please check them out. I used them to solve my problems when working with GridView.
 
Share this answer
 
Comments
jleonorlane 4-Jun-10 10:51am    
...well thank you..., but i figure it out already...
GregWyatt 4-Jun-10 10:56am    
No worries, still if you get the chance check out those articles they will allow you to do a lot with gridviews.
txtIL_ID.Text = dtgView.Rows(dtgView.SelectedRows(0)).Cells(1).Value
txtIL_Name.Text = dtgView.Rows(dtgView.SelectedRows(0)).Cells(3).Value
txtIL_Desc.Text = dtgView.Rows(dtgView.SelectedRows(0)).Cells(4).Value
...
 
Share this answer
 
Comments
jleonorlane 4-Jun-10 10:50am    
i've got an error "Value of Type DataGridViewRow cannot be converted to Integer"
Scubapro 6-Jun-10 14:15pm    
txtIL_ID.Text = Str(dtgView.Rows(dtgView.SelectedRows(0)).Cells(1).Value)

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