如何获取数据网格中选定行的值 [英] how to get the values of selected rows in datagrid

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

问题描述

当我按下[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...

推荐答案

本文可编辑ASP.NET 2.0中的GridView 和本文访问GridView控件内部的不同控件应该回答你的问题.它们是很好的文章,请检查出来.我使用它们来解决使用GridView时遇到的问题.
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.


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


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆