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

[Solved] Changing Color to particular column in Gridview

5 Answers 1042 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vidhya
Top achievements
Rank 1
Vidhya asked on 29 Oct 2010, 07:44 AM
hi....

in grid view how to change fore color,back color and set underline to particular column.

5 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 29 Oct 2010, 08:15 AM
Hello,

You can achieve the desired functionality by registering to the CellFormatting event, and check for that specific column, please take a look at the following example:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo.Name == "YOUR_COLUMN_NAME")
    {
        e.CellElement.ForeColor = Color.Blue;
        e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        e.CellElement.BackColor = Color.Red;
        e.CellElement.Font = new Font(e.CellElement.Font, FontStyle.Underline);
        e.CellElement.DrawFill = true;
    }
    else
    {
        e.CellElement.DrawFill = false;
        e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

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

Best Regards,
Emanuel Varga
0
Vidhya
Top achievements
Rank 1
answered on 29 Oct 2010, 08:26 AM
thank you very much...
its working...
0
Asish
Top achievements
Rank 1
answered on 12 Jan 2011, 02:59 PM
I am not getting cell formmatting event in xaml..Please help me
0
Richard Slade
Top achievements
Rank 2
answered on 12 Jan 2011, 04:04 PM
Hello,

It looks like your question might be for the Silverlight forums. If that's the case, please re-direct your question there.
Thanks
Richard
0
Vanya Pavlova
Telerik team
answered on 12 Jan 2011, 05:20 PM
Hello Vidhya,

 
CellFormatting event is specific to our RadGridView/WinForms and there is no exact equivalent in our RadGridView/Silverlight. You may use several approaches to achieve the same result based on your project requirements.
Some of the possible options are listed below:

1.You can create named styles targeted at GridViewCell and apply this style in RadGridView's columns as it is shown below:

<UserControl
    x:Class="SilverlightApplication147.MainPage"
    Width="640" Height="480">
    <UserControl.Resources>
        <Style x:Key="a1" TargetType="telerik:GridViewCell">
            <Setter Property="Background" Value="Red"/>
            <Setter Property="Foreground" Value="Black"/>
            <Setter Property="FontWeight" Value="Bold"/>
        </Style>
        <Style x:Key="a2" TargetType="telerik:GridViewCell">
            <Setter Property="Background" Value="Blue"/>
            <Setter Property="Foreground" Value="Yellow"/>
            <Setter Property="FontStyle" Value="Italic"/>
        </Style>
        <Style x:Key="a3" TargetType="telerik:GridViewCell">
            <Setter Property="Background" Value="Black"/>
            <Setter Property="Foreground" Value="PeachPuff"/>
        </Style>
        </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource SampleDataSource}}">
        <telerik:RadGridView  AutoGenerateColumns="False" ShowColumnFooters="True" ItemsSource="{Binding Collection}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn CellStyle="{StaticResource a1}" Header="Price" DataFormatString="{}{0:c}"  DataMemberBinding="{Binding Property1}"/>
                <telerik:GridViewDataColumn CellStyle="{StaticResource a2}" Header="Name" DataMemberBinding="{Binding Property3}"/>
                <telerik:GridViewDataColumn CellStyle="{StaticResource a3}" Header="CompanyName" DataMemberBinding="{Binding Property4}"/>
                 
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
         
    </Grid>
</UserControl>

2.You may also use the CellTemplateSelectors to apply some different datatemplate in specific column, please follow this link.

If you need any additional information please let me know.

Kind regards,
Vanya Pavlova
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Vidhya
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Vidhya
Top achievements
Rank 1
Asish
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Vanya Pavlova
Telerik team
Share this question
or