我想将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