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

RadGridView Cell Formatting Changine When I Resize the Grid

1 Answer 180 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 30 Mar 2011, 07:05 PM
Hi All,

I have a RadGridView that is showing some odd formatting issues when it is resized.  I am using the CellFormatting event to draw thick borders in the left side of the cells of a particular column to indicate a logical grouping of columns, however when I resize the grid this thick black left border appears in many other cells than the one I want it to.

Note: This worked fine until I updated my RadControls to Q1 2011.

So, here is my demo:
First I open the grid and all looks well.  I am using the CellFormatting event to draw the thick left border of some cells.
-See Attached Image "FirstOpened.PNG"

I then resize the grid, shrinking it about halfway.
-See Attached Image "Halfway.PNG"

Finally, I resize the Grid back to it's original size, which results in the odd formatting.  See that the thick left border has been applied to many cells and some BackColoring has also been changed.
-See Attached Image "OpenedAgain.PNG"

Here is my CellFormatting code:
private void grdHuntGroups_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
 
    //Set back color based on service level
    if (e.CellElement.ColumnInfo.HeaderText.ToLower() == "soa")
    {
        e.CellElement.BackColor = Color.Yellow;
        e.CellElement.DrawFill = true;
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        e.CellElement.BackColor = (Color)e.CellElement.RowInfo.Cells["SOABackColor"].Value;
        e.CellElement.ForeColor = (Color)e.CellElement.RowInfo.Cells["SOAForeColor"].Value;
    }
 
    //Set thick border to seperate sections
    if (e.CellElement.ColumnInfo.HeaderText.ToLower() == "lg-out"
        || e.CellElement.ColumnInfo.HeaderText.ToLower() == "pres"
        || e.CellElement.ColumnInfo.HeaderText.ToLower() == "soa")
    {
        e.CellElement.BorderLeftWidth = 8.0f;
        e.CellElement.BorderLeftColor = Color.Black;
        e.CellElement.DrawBorder = true;
    }
}


Do I need to change the way I am formatting the grid?  What has changed in this latest version that may have caused this?

Thanks in advance for any help ... I appreciate It!
-Matt

1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 31 Mar 2011, 07:55 AM
Hello Matt,

You should reset the changes you've made to the cell if the cell does not meet those conditions.
A first look reset would be:
private void grdHuntGroups_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
        {
            e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.FourBorders;
 
            //Set back color based on service level
            if (e.CellElement.ColumnInfo.HeaderText.ToLower() == "soa")
            {
                e.CellElement.BackColor = Color.Yellow;
                e.CellElement.DrawFill = true;
                e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                e.CellElement.BackColor = (Color)e.CellElement.RowInfo.Cells["SOABackColor"].Value;
                e.CellElement.ForeColor = (Color)e.CellElement.RowInfo.Cells["SOAForeColor"].Value;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
 
            //Set thick border to seperate sections
            if (e.CellElement.ColumnInfo.HeaderText.ToLower() == "lg-out"
                || e.CellElement.ColumnInfo.HeaderText.ToLower() == "pres"
                || e.CellElement.ColumnInfo.HeaderText.ToLower() == "soa")
            {
                e.CellElement.BorderLeftWidth = 8.0f;
                e.CellElement.BorderLeftColor = Color.Black;
                e.CellElement.DrawBorder = true;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.BorderLeftWidthProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.BorderRightColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
Matt
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or