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

After setting a different cell-Background, rows are not "highlighted" after selecting them!?

1 Answer 49 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 30 Jul 2012, 02:02 PM
Hello!

In my GridView, I'm alternating the background-color from transparent to some color for "columns-blocks". This is working.

Now, when I select a row, I want the whole row be higlighted in the typical orange color. After selecting another color, the "columns-blocks" should alternate again for the disselected row.

To better understand what I mean, a attached a screenshot.

Kind regards

Michael

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Aug 2012, 06:50 AM
Hello Michael,

Thank you for writing.

The desired appearance can be achieved by using the CellFormatting event of RadGridView. Here is a small
application demonstrating that:
public Form1()
{
    InitializeComponent();
 
    for (int i = 0; i < 10; i++)
    {
        radGridView1.Columns.Add("Column " + i);
    }
 
    for (int i = 0; i < 10; i++)
    {
        radGridView1.Rows.Add(i, i, i, i, i, i, i, i, i, i);
    }
 
    radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(radGridView1_CellFormatting);
}
 
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (!e.CellElement.RowInfo.IsCurrent &&
        (e.CellElement.ColumnInfo.Name == "Column 1" ||
         e.CellElement.ColumnInfo.Name == "Column 2" ||
         e.CellElement.ColumnInfo.Name == "Column 3" ||
         e.CellElement.ColumnInfo.Name == "Column 8"))
    {
        e.CellElement.BackColor = Color.AliceBlue;
        e.CellElement.DrawFill = true;
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
    }
    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);
    }
}

I hope that you find this information useful. Let us know if you have any other questions.
 
Kind regards,
Stefan
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or