This is a migrated thread and some comments may be shown as answers.

Setting BorderColor of cell

5 Answers 552 Views
GridView
This is a migrated thread and some comments may be shown as answers.
SUNIL
Top achievements
Rank 2
Iron
SUNIL asked on 23 Oct 2010, 04:49 PM
I want to set the border color of a cell element to red based on a condition in row formatting  event, but even when I set BorderColor = Color.Red, it does not work. Even setting border thickness of cell element does not work.
How would I do this in cell formatting event?
I am using Q1 2008 SP1 version. the code that I am using and it does not set border is as below.

Thanks
Sunil
if (e.RowElement != null && e.RowElement.RowInfo is GridViewDataRowInfo)
           {
               GridCellElement cellElement = e.RowElement.RowInfo.Cells["AttributeName"].CellElement;
               if (cellElement!=null && (int)e.RowElement.RowInfo.Cells["AttributeId"].Value == _duplicateRowIndex)
               {
                   cellElement.ForeColor= Color.Red;
                   cellElement.ToolTipText = "You input duplicate Attribute Name";
                   cellElement.BorderThickness = new Padding(1, 1, 1, 1);
                   cellElement.BorderColor = Color.Red;
                   cellElement.DrawBorder = true;
               }
               else
               {
                   cellElement.ResetValue(VisualElement.ForeColorProperty);
                   cellElement.ToolTipText = string.Empty;
                   cellElement.ResetValue(LightVisualElement.BorderColorProperty);
               }
           }

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 23 Oct 2010, 09:10 PM
Hello Sunil,

Try setting also the following:
cell.BorderBoxStyle = BorderBoxStyle.SingleBorder;
cell.BorderWidth = 2;

Please let me know if these help,

Best Regards,
Emanuel Varga
0
SUNIL
Top achievements
Rank 2
Iron
answered on 24 Oct 2010, 05:56 PM
Hello Emanuel,

The suggestion you gave did not help. There is no Widtn property on cell element in Q1 2008 SP1. So I tried the BorderThickness, but it has no effect. The code I tried is as below.

Thanks
Sunil
if ((int)e.CellElement.RowInfo.Cells["AttributeId"].Value == _duplicateRowIndex)
                {
                    e.CellElement.DrawBorder = true;
                    e.CellElement.DrawFill = true;
                    e.CellElement.ForeColor = Color.Red;
                    e.CellElement.ToolTipText = "You input duplicate Attribute Name";
                    e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder;
                    e.CellElement.BorderColor = Color.Red;
                    e.CellElement.BorderThickness = new Padding(1, 1, 1, 1);
                }
 
                else
                {
                    e.CellElement.ResetValue(VisualElement.ForeColorProperty);
                    e.CellElement.ToolTipText = string.Empty;
                    e.CellElement.ResetValue(LightVisualElement.BorderColorProperty);
                    e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty);
                    e.CellElement.BorderThickness = new Padding(0, 0, 0, 0);
                     
                }
0
SUNIL
Top achievements
Rank 2
Iron
answered on 24 Oct 2010, 06:29 PM
Hello Emanuel,

The following code worked. I had to set individual cells and also ResetBorderLeftProperty etc. caused the border to not draw.

Thanks
Sunil
if ((int)e.CellElement.RowInfo.Cells["AttributeId"].Value == _duplicateRowIndex)
                {
                    e.CellElement.DrawBorder = true;
                    //e.CellElement.DrawFill = true;
                    e.CellElement.ForeColor = Color.Red;
                    e.CellElement.ToolTipText = "You input duplicate Attribute Name";
                    e.CellElement.BorderBoxStyle = BorderBoxStyle.SingleBorder;
                    e.CellElement.BorderLeftColor = Color.Red;
                    e.CellElement.BorderLeftWidth = 1.0F;
                    e.CellElement.BorderRightColor = Color.Red;
                    e.CellElement.BorderRightWidth = 1.0F;
                    e.CellElement.BorderBottomColor = Color.Red;
                    e.CellElement.BorderBottomWidth = 1.0F;
                    e.CellElement.BorderTopColor = Color.Red;
                   e.CellElement.BorderTopWidth = 1.0F;
                }
 
                else
                {
                    e.CellElement.ResetValue(VisualElement.ForeColorProperty);
                    e.CellElement.ToolTipText = string.Empty;
                    e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty);
                   e.CellElement.ResetValue(LightVisualElement.BorderLeftColorProperty);
                    e.CellElement.BorderLeftWidth = 0.0F;
                    e.CellElement.ResetValue(LightVisualElement.BorderBottomColorProperty);
                    e.CellElement.BorderBottomWidth = 0.0F;
                    e.CellElement.ResetValue(LightVisualElement.BorderRightColorProperty);
                    e.CellElement.BorderRightWidth = 0.0F;
                    e.CellElement.ResetValue(LightVisualElement.BorderTopColorProperty);
                    e.CellElement.BorderTopWidth= 0.0F;
                    
                    
                     
                }
0
Emanuel Varga
Top achievements
Rank 1
answered on 24 Oct 2010, 06:36 PM
Hello Sunil,

I'm glad to hear that you have found your answer, and sorry that i couldn't help you more, like i said so many times, I'm positive that if you had used the latest version my suggestions would have worked.

Best Regards,
Emanuel Varga
0
SUNIL
Top achievements
Rank 2
Iron
answered on 24 Oct 2010, 10:00 PM
Hello Emanuel,

I appreciate all your help whether its the answer or not.
Upgrading to latest version is ok if you have one or two screens to take care of.
But when you have a big infrastructure with many screens, then upgrading is like hell, and veryyyyyyyyy difficult with Telerik controls.
So I am forced to use an older version.

I hope I could upgrade, but believe me, its very impractical unless I hire 2 programmers for 1 to 2 months, just to do my upgrade.

Thanks
Sunil
Tags
GridView
Asked by
SUNIL
Top achievements
Rank 2
Iron
Answers by
Emanuel Varga
Top achievements
Rank 1
SUNIL
Top achievements
Rank 2
Iron
Share this question
or