【问题标题】:Get row index in DataGrid获取 DataGrid 中的行索引
【发布时间】:2016-03-28 09:18:39
【问题描述】:

我在 asp.net (vb.net) 中有一个从数据库填充的数据网格,前两个字段是一个复选框和一个按钮图像。

我希望每当用户单击按钮时,都会打开另一个表单来编辑行的内容。问题是按钮正在由视觉工作室为每一行动态加载。如何知道按钮是从哪一行中选择的,以便传递该行的参数?

【问题讨论】:

    标签: asp.net .net vb.net datagrid


    【解决方案1】:

    您可以将 DataGrid/DataGridView 事件用作 CellClick、CellDoubleClick、CellContentClick... 并通过 e.RowIndex 或 e.ColumnIndex 获取。例如,

    Private Sub MyDataGridView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles MyDataGridView.CellClick
    
                If e.ColumnIndex = 8 Then 'only executed for cells at column 8
    
                    Dim newForm As New MyNewForm(e.RowIndex)
    
                    newForm.Show()
    
                End If
    
            End Sub
    

    并在 MyNewForm 上添加 Sub New 以检索行索引,

    Public Class MyNewForm
    
        Private intRowIndex As Integer
    
        Public Sub New(ByVal rowIndex As Integer)
    
            intRowIndex = rowIndex
    
            ' This call is required by the designer.
            InitializeComponent()
    
        End Sub
    ...
    

    【讨论】:

      猜你喜欢
      • 2014-02-20
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 2015-09-24
      • 2015-01-23
      • 2011-10-16
      • 2014-09-27
      相关资源
      最近更新 更多