如何获取数据网格中选定行的值

如何获取数据网格中选定行的值

本文介绍了如何获取数据网格中选定行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我按下[RETURN KEY]&时,如何获取数据网格中选定行的值?将其分发到文本框...

请帮忙...
这是我的代码...

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...

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...

推荐答案


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
...


这篇关于如何获取数据网格中选定行的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 03:33