Setting BorderColor of cell

6 posts, 0 answers
  1. Sunil
    Sunil avatar
    231 posts
    Member since:
    Jan 2004

    Posted 23 Oct 2010 Link to this post

    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);
                   }
               }
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 23 Oct 2010 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sunil
    Sunil avatar
    231 posts
    Member since:
    Jan 2004

    Posted 24 Oct 2010 Link to this post

    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);
                         
                    }
  5. Sunil
    Sunil avatar
    231 posts
    Member since:
    Jan 2004

    Posted 24 Oct 2010 Link to this post

    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;
                        
                        
                         
                    }
  6. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 24 Oct 2010 Link to this post

    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
  7. Sunil
    Sunil avatar
    231 posts
    Member since:
    Jan 2004

    Posted 24 Oct 2010 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready