Hi,
How to apply (by c# code) custom style (fore color, back color, font etc..) to only specific column, so style will affect all data in that column? I also want change style for individual column header cell and summary cell.
I'm only interested in the change of these properties in some of the columns, not all.
How to apply (by c# code) custom style (fore color, back color, font etc..) to only specific column, so style will affect all data in that column? I also want change style for individual column header cell and summary cell.
I'm only interested in the change of these properties in some of the columns, not all.
3 Answers, 1 is accepted
0
Accepted
Hello Dominik,
Thank you for writing.
To customize the appearance of the cells in RadGridView you should use the formatting events: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html. As stated in the article one should use the CellFormatting event to style the data cells and the ViewCellFormatting event for all cells.
1. To style your data cells you can use the following code:
2. To style a specific header cell you need to use the ViewCellFormatting event. Here is an example:
3. As to the summary cell, you will also need to use the ViewCellFormatting event handler:
Please take a look at the articles mentioned above for additional information and examples.
I hope this helps. Let me know if you have additional questions.
Kind regards,
Plamen
the Telerik team
Thank you for writing.
To customize the appearance of the cells in RadGridView you should use the formatting events: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html. As stated in the article one should use the CellFormatting event to style the data cells and the ViewCellFormatting event for all cells.
1. To style your data cells you can use the following code:
void
radGridView1_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"Status"
)
{
e.CellElement.ForeColor = Color.Red;
e.CellElement.BackColor = Color.Yellow;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.DrawFill =
true
;
}
else
{
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}
2. To style a specific header cell you need to use the ViewCellFormatting event. Here is an example:
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"Status"
&& e.CellElement
is
GridHeaderCellElement)
{
e.CellElement.BackColor = Color.Yellow;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.DrawFill =
true
;
}
else
{
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}
3. As to the summary cell, you will also need to use the ViewCellFormatting event handler:
void
radGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"Status"
&& e.CellElement
is
GridSummaryCellElement)
{
e.CellElement.BackColor = Color.Red;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.DrawFill =
true
;
}
else
{
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}
Please take a look at the articles mentioned above for additional information and examples.
I hope this helps. Let me know if you have additional questions.
Kind regards,
Plamen
the Telerik team
0

konrad
Top achievements
Rank 1
answered on 19 Dec 2012, 08:22 AM
Thank you for your answer!
For GridHeaderCellElement - work like a charm.
For GridCellElement work only if we have the data in the table. It is obvious.
The problem is that I need to read and modify the formatting of a cell in an empty grid. In other words, I need to set something like default format for the data which will appear in the future.
Basically I am looking for property like DefaultCellStyle in standard .NET DataGridView.
I know that I could temporarily add one row to perform this function but it is not a elegant solution.
For GridHeaderCellElement - work like a charm.
For GridCellElement work only if we have the data in the table. It is obvious.
The problem is that I need to read and modify the formatting of a cell in an empty grid. In other words, I need to set something like default format for the data which will appear in the future.
Basically I am looking for property like DefaultCellStyle in standard .NET DataGridView.
I know that I could temporarily add one row to perform this function but it is not a elegant solution.
0
Hello Dominik,
Thank you for writing back.
In my previous post I have missed the summary cell question. This is why I am going to edit it to add the omitted information and update the data cells sample.
Kind regards,
Plamen
the Telerik team
Thank you for writing back.
In my previous post I have missed the summary cell question. This is why I am going to edit it to add the omitted information and update the data cells sample.
Kind regards,
Plamen
the Telerik team