Description:
Can I draw a box around the selected cell? I need to implement an Excel-type cell focus rectangle.
Answer:
This article explains three different approaches to accomplishing this. It's up to you to decide which one to use.
-
Use the custom drawing feature of the XtraGrid, namely, the GridView.CustomDrawCell event. The specifics of this approach is that you have to fully paint the cell's interior and then draw a thick border over it. You can draw the editors' contents by calling the e.DefaultDraw method (or the grid's internal method in older versions of our components). This approach is shown in the How to draw thick cell borders by handling the CustomDrawCell event example.
A cell's border painted via the CustomDrawCell event handler is displayed only when the cell is not being edited. When the in-place editor is opened, it paints itself and does not support custom drawing. However, you can draw borders for the different cells of your grid, not just for the focused cell, and use different colors for them. Thus, you can use this solution for highlighting cells as an alternative to cell styles (see the Assigning Styles to Individual Cells help topic). -
Use the PaintEx (starting with version 17.2 of our components) or Paint event (in older versions) as shown in the How to draw thick cell borders by handling the Paint event example. The basic idea of this approach is to handle the Paint/PaintEx event, obtain GridViewInfo and GridCellInfo objects to calculate a cell's bounds and paint a border around the focused cell. All this work is done by the special HotTrackCellHelper class implemented in the scope of the How to draw thick cell borders by handling the Paint event example.
See Also:
Custom Painting Basics
How to draw a rectangle around selected cells and implement a copy/paste functionality
How to merge cells horizontally in GridView
How to copy a cell's value to other cells by dragging its right bottom edge