vb.net DevExperess winforms gridview鼠标down事件 [英] vb.net DevExperess winforms gridview mouse down event
本文介绍了vb.net DevExperess winforms gridview鼠标down事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题 MouseDown
事件 GridControl
与 GridView
。
如果用户按控制 + shift + 点击列标题是选择列,还点击最左上方将选择所有行。我设法做到这一点,但任何一个将为我的代码工作。似乎逻辑在 if-else
语句中有一些问题。任何人都可以帮忙
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
推荐答案
您可以使用 Select Case
语句重新排列您的语句。
这里是例子:
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
这篇关于vb.net DevExperess winforms gridview鼠标down事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文