当我在当前处于活动状态的 datagridview2 的某个事件处理程序中时,我必须知道在另一个(非活动)datagridview1 上选择了哪一行 datagridview1(MultiSelect = False)。
我尝试了一堆尝试,但没有正确的结果。
Private Sub DataGridView2_CellDoubleClick(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView2.CellDoubleClick
Dim myindex1 As Integer = DataGridView1.CurrentCell.RowIndex
OR
Dim myindex1 As Integer = DataGridView1.CurrentRow.Index
当 datagridview1 处于活动状态并且我从他们的事件处理程序中获取索引时,这些都不起作用。
我应该怎么做以及如何准确地从第二个 datagridview 的事件处理程序中获取第一个 datagridview 的选定行?
编辑:添加代码:
Private Sub datagridview1_RowLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowLeave
selrow1 = e.RowIndex
End Sub
Private Sub datagridview1_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint
e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus
End Sub
Private Sub datagridview1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.GotFocus
DataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.FromKnownColor(KnownColor.Highlight)
End Sub
Private Sub datagridview1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.LostFocus
DataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.FromKnownColor(KnownColor.InactiveCaption)
End Sub