Example E513
Visible to All Users

WinForms Data Grid - Draw a thick border around the focused cell (CustomDrawCell event)

This example handles the CustomDrawCell event to paint a thick border around the focused cell.

C#
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { GridView view = sender as GridView; if (e.Column == view.FocusedColumn && e.RowHandle == view.FocusedRowHandle) { e.DefaultDraw(); CellDrawHelper.DrawCellBorder(e); e.Handled = true; } }

Files to Review

Documentation

See Also

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Form1.cs(vb)
C#
using DevExpress.LookAndFeel; using DevExpress.XtraGrid.Views.Grid; using System; using System.Drawing; namespace CellBorder { public partial class Form1 : DevExpress.XtraBars.Ribbon.RibbonForm { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, System.EventArgs e) { new DevExpress.XtraGrid.Design.XViewsPrinting(gridControl1); } private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { GridView view = sender as GridView; if (e.Column == view.FocusedColumn && e.RowHandle == view.FocusedRowHandle) { e.DefaultDraw(); CellDrawHelper.DrawCellBorder(e); e.Handled = true; } } } public static class CellDrawHelper { public static void DrawCellBorder(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { int penWidth = 3; Rectangle frameBounds = e.Bounds; string skinName = UserLookAndFeel.Default.SkinName; if (skinName != "WXI" && skinName != "WXI Compact") { penWidth = 2; frameBounds = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width + 1, e.Bounds.Height + 1); } penWidth = penWidth * (int)Math.Ceiling(e.Cache.ScaleDPI.ScaleFactorHorz - 0.5); Pen _pen = e.Cache.GetPen(DXSkinColors.ForeColors.ControlText, penWidth); e.Cache.DrawRectangle(_pen, frameBounds); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.