vb.net DevExperess winforms gridview mouse down event

ぃ、小莉子 提交于 2019-12-08 08:27:05

问题


I have a problem with MouseDown event for GridControl with GridView. If user press control + shift + click column header is to select the column and also click the most top left will select all row. I managed to do that but either one will work for my code. It seems the logic have some problem with if-else statement. Anyone can help?

Private Sub gridView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles GridView1.MouseDown
    If Control.ModifierKeys = (Keys.Control) Then
        Dim view As GridView = CType(sender, GridView)
        Dim hInfo As GridHitInfo = view.CalcHitInfo(e.Location)
        If hInfo.InColumn Then
            view.ClearSelection()
            SelectCells(hInfo.Column)
        Else
            Return
        End If
        CType(e, DXMouseEventArgs).Handled = True
    ElseIf Control.ModifierKeys = Nothing Then
        Dim view As GridView = CType(sender, GridView)
        view.ClearSelection()
        Return
    Else
        Dim view2 As GridView = CType(sender, GridView)

        Dim hitInfo As GridHitInfo = view2.CalcHitInfo(e.Location)

        If hitInfo.HitTest = GridHitTest.ColumnButton Then
            view2.SelectAll()
        End If
        CType(e, DXMouseEventArgs).Handled = True

    End If

End Sub

Private Sub SelectCells(ByVal column As GridColumn)
    Dim view As GridView = CType(column.View, GridView)

    view.BeginSelection()
    For i As Integer = 0 To column.View.RowCount - 1
        view.SelectCell(i, column)
    Next i
    view.EndSelection()
End Sub

回答1:


You can use Select Case statement to rearrange your statements.
Here is example:

Private Sub gridView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles gridView1.MouseDown

    Dim view As GridView = CType(sender, GridView)
    Dim hInfo As GridHitInfo = view.CalcHitInfo(e.Location)

    Select Case True
        Case hInfo.HitTest = GridHitTest.ColumnButton
            view.SelectAll()
        Case Control.ModifierKeys = Nothing
            view.ClearSelection()
            Return
        Case hInfo.InColumn AndAlso Control.ModifierKeys = (Keys.Shift Or Keys.Control)
            view.ClearSelection()
            SelectCells(hInfo.Column)
        Case Else
            Return
    End Select

    CType(e, DXMouseEventArgs).Handled = True

End Sub


来源:https://stackoverflow.com/questions/33541088/vb-net-devexperess-winforms-gridview-mouse-down-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!