Setting the border brush on a single cell

I am trying to set the border brush on a a single cell using this code:

// This line of code runs without an exception
dataGrid.Model[RowIndex, ColumnIndex].Borders.Bottom.Brush = (SolidColorBrush)Resources["brushInvalidDataColor"];

// This line fails wiith NullReferenceException
dataGrid.Model[RowIndex, ColumnIndex].Borders.Left.Brush = (SolidColorBrush)Resources["brushInvalidDataColor"];

// This line of code runs without an exception
dataGrid.Model[RowIndex, ColumnIndex].Borders.Right.Brush = (SolidColorBrush)Resources["brushInvalidDataColor"];

// This line fails wiith NullReferenceException
dataGrid.Model[RowIndex, ColumnIndex].Borders.Top.Brush = (SolidColorBrush)Resources["brushInvalidDataColor"];

If I remove the lines causing the NullReferenceException the code runs but the border of every cell is changed - not just the one cell at RowIndex, ColumnIndex.

I want to set the border color of a single cell - how do I do that?

1 Reply

MN Muthulakshmi N Syncfusion Team August 25, 2010 11:13 AM UTC

Hi William,

Thank you for your details.

Using the below code you can apply the border color for a single cell of Grid Control.

[C# Code]

grid.Model[4, 3].Borders.Left = new Syncfusion.Windows.Pen(new SolidColorBrush(Colors.Red), 2.0);
grid.Model[4, 3].Borders.Right = new Syncfusion.Windows.Pen(new SolidColorBrush(Colors.Red), 2.0);
grid.Model[4, 3].Borders.Top = new Syncfusion.Windows.Pen(new SolidColorBrush(Colors.Red), 2.0);
grid.Model[4, 3].Borders.Bottom = new Syncfusion.Windows.Pen(new SolidColorBrush(Colors.Red), 2.0);

Let us know if you need any details.

Thanks,
Muthulakshmi

Loader.
Up arrow icon