次のサンプルコードは、このメソッドを使用してセルのマウス動作をカスタマイズする方法を示します。このサンプルコードは、
IEditingCellインタフェースに示されている詳細なコード例の一部を抜粋したものです。
bool _beginMouseDraging = false;
protected override void OnMouseDown(CellMouseEventArgs e)
{
// Override OnMouseDown method to customize the action when mouse down the cell.
if (e.Button == MouseButtons.Left)
{
// Assert the cell is current cell.
if (this.GcMultiRow.CurrentCell.RowIndex == e.RowIndex &&
this.GcMultiRow.CurrentCell.CellIndex == e.CellIndex)
{
bool beginEditSuccess = this.GcMultiRow.BeginEdit(false);
if (beginEditSuccess)
{
this.EditingCellFormattedValue = this.GetValueFromPoint(e.Location);
this._beginMouseDraging = true;
}
}
}
base.OnMouseDown(e);
}
protected override void OnMouseMove(CellMouseEventArgs e)
{
if (this._beginMouseDraging)
{
// Mouse dragging to change the EditingCellFormattedValue.
this.EditingCellFormattedValue = this.GetValueFromPoint(e.Location);
}
base.OnMouseMove(e);
}
protected override void OnMouseUp(CellMouseEventArgs e)
{
// When mouse up, end dragging.
this._beginMouseDraging = false;
base.OnMouseUp(e);
}
Private _beginMouseDraging As Boolean = False
Protected Overloads Overrides Sub OnMouseDown(ByVal e As CellMouseEventArgs)
' Override OnMouseDown method to customize the action when mouse down the cell.
If e.Button = MouseButtons.Left Then
' Assert the cell is current cell.
If Me.GcMultiRow.CurrentCell.RowIndex = e.RowIndex AndAlso Me.GcMultiRow.CurrentCell.CellIndex = e.CellIndex Then
Dim beginEditSuccess As Boolean = Me.GcMultiRow.BeginEdit(False)
If beginEditSuccess Then
Me.EditingCellFormattedValue = Me.GetValueFromPoint(e.Location)
Me._beginMouseDraging = True
End If
End If
End If
MyBase.OnMouseDown(e)
End Sub
Protected Overloads Overrides Sub OnMouseMove(ByVal e As CellMouseEventArgs)
If Me._beginMouseDraging Then
' Mouse dragging to change the EditingCellFormattedValue.
Me.EditingCellFormattedValue = Me.GetValueFromPoint(e.Location)
End If
MyBase.OnMouseMove(e)
End Sub
Protected Overloads Overrides Sub OnMouseUp(ByVal e As CellMouseEventArgs)
' When mouse up, end dragging.
Me._beginMouseDraging = False
MyBase.OnMouseUp(e)
End Sub