vb.net DexExpress winform GridControl单击列标题选择单元格

时间:2015-11-05 02:52:58

标签: vb.net winforms gridview devexpress

我使用GridviewBandedGridview来显示数据。我意识到我点击列标题正在排序数据而不是选择列标题下的所有单元格。我可以知道如何处理吗?我有一个示例代码(如下),但它使用Private Sub bandedGridView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles bandedGridView1.MouseDown If Control.ModifierKeys <> (Keys.Shift Or Keys.Control) Then Return End If Dim view As BandedGridView = CType(sender, BandedGridView) Dim hInfo As BandedGridHitInfo = view.CalcHitInfo(e.Location) If hInfo.InColumn Then view.ClearSelection() SelectCells(hInfo.Column) ElseIf hInfo.InBandPanel AndAlso hInfo.Band IsNot Nothing Then view.ClearSelection() SelectCells(hInfo.Band) Else Return End If CType(e, DXMouseEventArgs).Handled = True End Sub Private Sub SelectCells(ByVal column As BandedGridColumn) For i As Integer = 0 To column.View.RowCount - 1 column.View.SelectCell(i, column) Next i End Sub Private Sub SelectCells(ByVal band As GridBand) For Each column As BandedGridColumn In band.Columns SelectCells(column) Next column End Sub

GridView

我只需要{{1}},任何人都可以提供帮助吗?

1 个答案:

答案 0 :(得分:1)

如果您要将此代码用于GridView,那么您只需从任意位置删除Banded一词,并删除属于GridBand的任何内容。对于SelectedCells方法,您需要将column.View转换为GridView。另外,我建议您将GridView.BeginSelectionGridView.EndSelection方法添加到SelectedCells方法中 这是一个例子:

Imports DevExpress.Utils
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo

'...

Private Sub gridView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles gridView1.MouseDown
    If Control.ModifierKeys <> (Keys.Shift Or Keys.Control) Then
        Return
    End If
    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
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 view.RowCount - 1
        view.SelectCell(i, column)
    Next i

    view.EndSelection()
End Sub