Articles in this section
Category / Section

How to customize current cell background and border color in WPF GridControl?

3 mins read

WPF GridControl allows to customize the current cell appearance. You can show the border for current cell by using GridControl.Model.Options.ShowCurrentCell property.

Below is the screen shot when ShowCurrentCell is true.

Show the current cell in GridControl

Below is the screen shot when ShowCurrentCell is false.

Hide the current cell in GridControl

Excel-like Border for CurrentCell

You can change the appearance of current cell similar to Excel by setting GridControl.Model.Options.ShowCurrentCell and GridControl.Model.Options.ExcelLikeCurrentCell properties to true.

C#

//Using ShowCurrentCell property.
grid.Model.Options.ShowCurrentCell = true;
 
//Using ExcelLikeCurrentCell property.
grid.Model.Options.ExcelLikeCurrentCell = true;

 

Show the current cell without background

Show the current cell without background

Change current cell background and border color

You can change the current cell background color from white to the selection color to look uniform with selected cells by setting the GridControl.Model.Options.ShowCurrentCell property to false. Current cell can be shown with border outline using QueryCellInfo and SelectionChanged events when ShowCurrentCell is false.

C#

grid.Model.Options.ActivateCurrentCellBehavior = Syncfusion.Windows.Controls.Grid.GridCellActivateAction.DblClickOnCell;
gridControl.Model.Options.ShowCurrentCell = false;
 
grid.Model.SelectionChanged += Model_SelectionChanged;
grid.Model.QueryCellInfo += Model_QueryCellInfo;
 
private void Model_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
    if (e.Reason == GridSelectionReason.MouseDown || e.Reason == GridSelectionReason.MouseUp)
    {
        grid.InvalidateCells();
    }
}
 
private void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
    //show border for current cell while selecting the set of cells
    if (grid.Model.SelectedRanges.ActiveRange.Contains(GridRangeInfo.Cell(e.Cell.RowIndex, e.Cell.ColumnIndex)))
    {
        if(e.Cell.RowIndex == grid.CurrentCell.RowIndex && e.Cell.ColumnIndex == grid.CurrentCell.ColumnIndex)
        {
            e.Style.Borders.All = new Pen(Brushes.Black, 2);
        }
    }
    //show border for select the single cell or current cell
    if (e.Cell.RowIndex == grid.CurrentCell.RowIndex && e.Cell.ColumnIndex == grid.CurrentCell.ColumnIndex)
        e.Style.Borders.All = new Pen(Brushes.Black, 2);
}

 

Change current cell background color with outline border

Change current cell background color with outline border

Sample: View sample in GitHub  


Conclusion

I hope you enjoyed learning about how to customize current cell background and border color in WPF GridControl.

You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Grid documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied