注册 登录
编程论坛 VB.NET论坛

用右键单击行头换行之前能不能先发生`_RowValidating事件。 帮忙

shsoo99 发布于 2008-09-04 16:29, 1000 次点击
用右键单击行头换行之前能不能先发生`_RowValidating事件
Private Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
        Dim hti As Windows.Forms.DataGridView.HitTestInfo
        hti = Me.DataGridView1.HitTest(e.X, e.Y)
        '選択行の索引
        Dim selectindex As Integer = hti.RowIndex
        '選択行
        Dim dgr As DataGridViewRow = DataGridView1.Rows(selectindex)
        If e.Button = Windows.Forms.MouseButtons.Right And hti.Type = DataGridViewHitTestType.RowHeader Then
            dgr.HeaderCell.ContextMenuStrip = ContextMenuStrip1
            'DataGridView1.ContextMenuStrip = Me.ContextMenuStrip1
            Me.DataGridView1.Focus()
        Else
            DataGridView1.ContextMenuStrip = Nothing
            Exit Sub
        End If

      

        If selectindex >= 0 And DataGridView1.SelectedRows.Count >= 0 Then

            Me.DataGridView1.ClearSelection()


            DataGridView1.Rows(selectindex).DefaultCellStyle.SelectionBackColor = Nothing
            DataGridView1.Rows(selectindex).DefaultCellStyle.SelectionForeColor = Nothing

            dgr.Selected = True

★★  在这里能不能先触发`_RowValidating事件,然后再选中行???????????
            dgr.DataGridView.CurrentCell = dgr.DataGridView.Rows(selectindex).Cells(1)

        ElseIf selectindex >= 0 And DataGridView1.SelectedRows.Contains(dgr) Then

        DataGridView1.ClearSelection()

        dgr.Selected = True

        dgr.DataGridView.CurrentCell = dgr.DataGridView.Rows(selectindex).Cells(1)
        End If
    End Sub
0 回复
1