从排序和数据绑定的datagridview检索值

时间:2018-07-17 12:31:38

标签: vb.net data-binding datagridview

我想将gActiveRowIndex设置为它在数据表中的行的索引,即使datagridview已排序。

只有在未对datagridview进行排序的情况下,我才能使用,我正在寻找一种方法来将gActiveRowIndex设置为数据表中与单击的datagridview的行相对应的行的索引。

数据表:

Dim CustomerDataTable = New DataTable("Customer Data")
CustomerDataTable.Columns.Add("Customer Id", GetType(Integer))
CustomerDataTable.PrimaryKey = {CustomerDataTable.Columns("Customer Id")}
CustomerDataTable.Columns.Add("Firm und Customer Name")
CustomerDataTable.Columns.Add("Zip City")
CustomerDataTable.Columns.Add("Street")

表格:

Dim customerDataTable As DataTable

Sub getAdoRecords(dt As DataTable)
    customerDataTable = dt
    dgv_Search_Results.DataSource = dt
End Sub

Private Sub dgv_Search_Results_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_Search_Results.CellClick
    If e.RowIndex >= 0 Then
        gActiveRowIndex = e.RowIndex
        gActiveCustomerId = customerDataTable.Rows(e.RowIndex)(0)
        RaiseEvent SelectedValueChanged(sender, e)
        Close()
    End If
 End Sub

0 个答案:

没有答案