我使用Gridview
和BandedGridview
来显示数据。我意识到我点击列标题正在排序数据而不是选择列标题下的所有单元格。我可以知道如何处理吗?我有一个示例代码(如下),但它使用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}},任何人都可以提供帮助吗?
答案 0 :(得分:1)
如果您要将此代码用于GridView
,那么您只需从任意位置删除Banded
一词,并删除属于GridBand
的任何内容。对于SelectedCells
方法,您需要将column.View
转换为GridView
。另外,我建议您将GridView.BeginSelection
和GridView.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