I have custom modes/renderers for my row and column headers. I added code to handle mouse events and now the selection of rows, columns, table, etc isn''t working and I can''t figure out why.
The code I''ve added that causes it to break is as follows:
protected override void OnMouseDown(int rowIndex, int colIndex, MouseEventArgs e)
{
base.OnMouseDown(rowIndex, colIndex, e);
if (e.Button == MouseButtons.Left)
{
mouseDownCell_ = new Point(colIndex, RowIndex);
mouseDown_ = true;
this.Grid.InvalidateRange(GridRangeInfo.Cell(rowIndex, colIndex));
}
}
protected override void OnMouseUp(int rowIndex, int colIndex, MouseEventArgs e)
{
base.OnMouseUp(rowIndex, colIndex, e);
if (mouseDown_ && e.Button == MouseButtons.Left)
{
mouseDown_ = false;
this.Grid.InvalidateRange(GridRangeInfo.Cell(rowIndex, colIndex));
}
}
protected override void OnMouseMove(int rowIndex, int colIndex, MouseEventArgs e)
{
base.OnMouseMove(rowIndex, colIndex, e);
if (mouseDown_)
{
if (mouseDownCell_ != new Point(colIndex, RowIndex))
{
mouseDown_ = false;
this.Grid.InvalidateRange(GridRangeInfo.Cell(rowIndex, colIndex));
}
}
}
protected override int OnHitTest(int rowIndex, int colIndex, MouseEventArgs e, IMouseController controller)
{
if (controller != null && controller.Name == "OleDataSource")
// other controllers have higher priority than me
return 0;
return 1;
}
If I comment out the code, everything works fine. What am I missing?
Thanks
AD
Administrator
Syncfusion Team
July 20, 2004 03:57 PM UTC
When you return nonzero in OnHitTest, then no other mouse controller will get the mouse actions. So, the SelectCells controller will not get a chance to do anything.
So, if you want the default behavior to take place you cannot return nonzero in OnHitTest.
One possible solution would be to do all the processing you want to do from OnHitTest, and just return 0. You can test Control.MouseButtons to see if a particular button is pressed in OnHitTest.
AD
Administrator
Syncfusion Team
July 20, 2004 04:13 PM UTC
Oh, okay. So there''s no method to chain them together then or to pass the mouse events over to another controller?
AD
Administrator
Syncfusion Team
July 20, 2004 04:47 PM UTC
You can try code like this:
Syncfusion.Windows.Forms.IMouseController selectController = this.grid.MouseControllerDispatcher.Find("DragSelect");
selectController.MouseDown(e); //call mousedown
Now I haven''t actually tried this so I am not 100% sure it will work as you need things to work.