I'm not sure if this is a bug or if I'm missing something, but I'm trying to change the mouse cursor of a grid on the MouseDown event, but it doesn't work. This line of code:
Me.GridControl1.Cursor.Current = System.Windows.Forms.Cursors.Hand
in the MouseDown event will cause the mouse cursor to change momentarily to a hand, then back to the default arrow. Also, when I try to set the Cursor property of the grid at design time, it doesn't seem to affect anything at all (and, on some grids, the property reverts back to Default after running the program).
Am I missing something here?
AD
Administrator
Syncfusion Team
May 16, 2003 04:06 PM UTC
Essential Grid uses a MouseController architecture to manage mouse actions. The reason is that it is constantly checking to see if the mouse is over one of the spots it needs to handle, say over a grid cell border for sizing, or over the border of a selection for ole D&D, or over a column header, or ???.
So, if you want to control a cursor, you should create a class that implements IMouseController, and regiater this controller with the grid. Then your controller.HitTest will be called by the grid as the mouse moves. Depending on where the mouse is, your hittest should return nonzero when you want the control of the mouse. While your controller has control of the mouse, it gets all the msssages like MouseMove and MouseDown etc, and in addition it gets control of the cursor which it can set.
If you look at the CellButtons sample and the ExcelSelectionMarker sample, you can see examples of mouse controllers. You can also submit Direct Trac, and request other samples if you like.
CH
Charles Hanson
September 15, 2003 12:44 PM UTC
Is there any sort of documentation for mouse controllers? I'm looking at the samples, but there are no comments in the code and I am having trouble figuring out exactly what I should be doing in the various methods. Some direction on what 'HitTest', 'CancelMode', and 'GetBounds' are supposed to be doing would be great.
AD
Administrator
Syncfusion Team
September 15, 2003 04:02 PM UTC
HitTest should return nonzero exactly when you want your mousecontroller to have control (ie. provide the cursor, handle all mouse actions, etc.) When you no longer want control, it should return 0.
CancelMode is called for the active controller after a MouseDown message when the mouse operation is canceled. You should use it to clean up anything. Maybe you are dragging a rectangle across the screen when the action is canceled. You might use CancelMode to erase the last rectangle.
GetBounds is not a member of IMouseController, so I am not sre what it usage is. Is you question bsed on a particular sample?
GetBoun
CH
Charles Hanson
September 16, 2003 11:57 AM UTC
I'm looking at this code from ExcelMarker:
Public Overridable Overloads Function HitTest(ByVal e As MouseEventArgs, ByVal controller As IMouseController) As Integer Implements IMouseController.HitTest
lastHitTestCode = GridHitTestContext.None
' Our vote has higher priority than other controllers
If e.Button = MouseButtons.Left Then '&&
' (controller == null || controller.Name == "ResizeCells")
Dim range As GridRangeInfo = owner.Selections.Ranges.ActiveRange
If Not range.IsEmpty Then
Dim point1 As Point = New Point(e.X, e.Y)
point1.Offset(-delta, -delta)
Dim rowIndex, colIndex As Integer
owner.PointToRowCol(point1, rowIndex, colIndex)
If rowIndex = range.Bottom And colIndex = range.Right Then
point1.Offset(delta * 2 + 1, delta * 2 + 1)
Dim rowIndex2, colIndex2 As Integer
owner.PointToRowCol(point1, rowIndex2, colIndex2)
If rowIndex2 <> rowIndex And colIndex2 <> colIndex Then
lastHitTestCode = HitExcelMarker
End If
End If
End If
End If
Return lastHitTestCode
End Function 'HitTest
And I'm trying to figure out enough about what it's doing to adapt it for what we want to do. Basically we want to accomplish two things. First, we want a 'Click' event to fire every time a column header is clicked regardless of whether we have selected a column, not selected a column, are able to drag columns, etc. Secondly we do NOT want to display the drag icon whenever a column header is selected unless the user is actually holding the mouse button down and dragging with it.
CH
Charles Hanson
September 16, 2003 11:57 AM UTC
I'm looking at this code from ExcelMarker:
Public Overridable Overloads Function HitTest(ByVal e As MouseEventArgs, ByVal controller As IMouseController) As Integer Implements IMouseController.HitTest
lastHitTestCode = GridHitTestContext.None
' Our vote has higher priority than other controllers
If e.Button = MouseButtons.Left Then '&&
' (controller == null || controller.Name == "ResizeCells")
Dim range As GridRangeInfo = owner.Selections.Ranges.ActiveRange
If Not range.IsEmpty Then
Dim point1 As Point = New Point(e.X, e.Y)
point1.Offset(-delta, -delta)
Dim rowIndex, colIndex As Integer
owner.PointToRowCol(point1, rowIndex, colIndex)
If rowIndex = range.Bottom And colIndex = range.Right Then
point1.Offset(delta * 2 + 1, delta * 2 + 1)
Dim rowIndex2, colIndex2 As Integer
owner.PointToRowCol(point1, rowIndex2, colIndex2)
If rowIndex2 <> rowIndex And colIndex2 <> colIndex Then
lastHitTestCode = HitExcelMarker
End If
End If
End If
End If
Return lastHitTestCode
End Function 'HitTest
And I'm trying to figure out enough about what it's doing to adapt it for what we want to do. Basically we want to accomplish two things. First, we want a 'Click' event to fire every time a column header is clicked regardless of whether we have selected a column, not selected a column, are able to drag columns, etc. Secondly we do NOT want to display the drag icon whenever a column header is selected unless the user is actually holding the mouse button down and dragging with it.
AD
Administrator
Syncfusion Team
September 16, 2003 12:45 PM UTC
This code is trying to decide whether the mouse position passed in is over the lower right corner of a selected range of cells. If it is, then it sets the return value to a nonzero value. If it is not, then it returns whatever is stored in the lastHit value. This might be nonzero or not. The lastHit is turned off when you have finished dragging the selections or if you cancel out of it. It is only turned on in the HitTest.
This is what this code is trying to do.
I think in your case, you would want HitTexst to return nonzero when you are over a header cell. Then your handles like MouseDown and MouseMove will keep getting the events until you return nonzero in the hittest.