Syncfusion.Grid.Windows
Example 


CurrentCell Property (GridControlBase)

Gets GridCurrentCell object that provides storage for current cell information and manages all current cell operation such as activating, deactivating, saving, editing, and moving the current cell.
Syntax
'Declaration
 
<BrowsableAttribute(False)>
<DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)>
Public Overridable ReadOnly Property CurrentCell As GridCurrentCell
'Usage
 
Dim instance As GridControlBase
Dim value As GridCurrentCell
 
value = instance.CurrentCell
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual GridCurrentCell CurrentCell {get;}
Remarks
CurrentCell gives you a one stop interface for all current cell related operations. This is useful for an Intellisense-based programming environment since you do not have to dig through many unrelated functions.

Events for the current cell will be raised by the GridControlBase itself. The grid offers many events for the current cell that let you customize the current cell's behavior at any stage of operation.

You can find out about the current cell's position by querying the GridCurrentCell.RowIndex and GridCurrentCell.ColIndex properties of the CurrentCell object in GridControlBase. The GridCurrentCell.HasCurrentCell property tells you if the grid has an active current cell. The GridCurrentCell.HasCurrentCellAt method lets you find out if the current cell is at a specific row and column index.

See GridCurrentCell.MoveTo for a discussion about the order of events that you receive when the current cell is moved.

Example
The following example shows how you can customize the behavior of the current cell and highlight the whole row of the current cell instead of just the current cell itself.
/// Current cell will be moving from one position to another.
protected override void OnCurrentCellMoving(GridCurrentCellMovingEventArgs e)
{
    e.Options |= GridSetCurrentCellOptions.BeginEndUpdate;
    // Instead of GridSetCurrentCellOptions.BeginEndUpdate we could also
    // sandwich the call in a Begin/EndUpdate pair ourselves ...
    //BeginUpdate(BeginUpdateOptions.InvalidateAndScroll);
}
            
/// Completes a current cell's MoveTo operation indicating success.
protected override void OnCurrentCellMoved(GridCurrentCellMovedEventArgs e)
{
    base.OnCurrentCellMoved(e);
    //EndUpdate();
}
            
/// Completes a current cell's MoveTo operation indicating failure.
protected override void OnCurrentCellMoveFailed(GridCurrentCellMoveFailedEventArgs e)
{
    base.OnCurrentCellMoveFailed(e);
    //EndUpdate();
}
            
/// Highlight the current row.
protected override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
{
    if (e.RowIndex > this.Model.Rows.HeaderCount && e.ColIndex > this.Model.Cols.HeaderCount
        && CurrentCell.HasCurrentCellAt(e.RowIndex))
    {
        e.Style.Interior = new BrushInfo(SystemColors.Highlight);
        e.Style.TextColor = SystemColors.HighlightText;
        e.Style.Font.Bold = true;
    }
    base.OnPrepareViewStyleInfo(e);
}
            
/// Refresh the whole row for the old position of the current cell when it is moved to
/// a new row or when current cell is deactivated stand-alone.
protected override void OnCurrentCellDeactivated(GridCurrentCellDeactivatedEventArgs e)
{
    // Check if Deactivate is called stand-alone or called from MoveTo and row is moving.
    if (!CurrentCell.IsInMoveTo || CurrentCell.MoveToRowIndex != CurrentCell.MoveFromRowIndex)
    {
        RefreshRange(GridRangeInfo.Row(e.RowIndex), GridRangeOptions.MergeAllSpannedCells);
    }
    base.OnCurrentCellDeactivated(e);
}
            
/// Refresh the whole row for the new current cell position when the current cell is moved
/// to a new row or when current cell is activated stand-alone (and there was no activated current cell).
protected override void OnCurrentCellActivated(EventArgs e)
{
    // Check if Activate is called stand-alone or called from MoveTo and row is moving
    base.OnCurrentCellActivated(e);
    if (!CurrentCell.IsInMoveTo || CurrentCell.MoveToRowIndex != CurrentCell.MoveFromRowIndex
        || !CurrentCell.MoveFromActiveState)
    {
        RefreshRange(GridRangeInfo.Row(CurrentCell.RowIndex), GridRangeOptions.MergeAllSpannedCells);
    }
}
AssemblyVersion

Syncfusion.Grid.Windows: 17.3460.0.14

See Also