RSS

How to change row color for RadGrid with specified conditions?

19 Dec

this Post define if you want to change color of Negative value in cell to change the red color .this article help u which i implement in his project.

 

<telerik:RadGridView x:Name=”grdCompaignList” IsFilteringAllowed=”True”  ShowColumnFooters=”True”  RowIndicatorVisibility=”Visible”
AutoGenerateColumns=”False” HorizontalAlignment=”Center” CanUserFreezeColumns=”False” CanUserResizeColumns=”False”
ShowGroupPanel=”False” Margin=”3,0″ Grid.Row=”0″ BorderThickness=”1″  Style=”{StaticResource DefaultGridStyle}” MinWidth=”850″ MaxWidth=”900″ RowLoaded=”grdCompaignList_RowLoaded”>
<telerik:RadGridView.Columns>

<telerik:GridViewDataColumn Header=”Company Number” IsReadOnly=”True”
DataMemberBinding=”{Binding Number, Mode=TwoWay}” Width=”.2*”>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding Number}” />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>

</telerik:GridViewDataColumn>

<telerik:GridViewDataColumn Header=”Name”
DataMemberBinding=”{Binding Name, Mode=TwoWay}” Width=”.2*”>
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<TextBlock Text=”{Binding Name}” />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>

</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn Header=”Budget”
DataMemberBinding=”{Binding Budjet, Mode=TwoWay}”
DataFormatString=”{}{0:c}” TextAlignment=”Right” Width=”.1*”>
<telerik:GridViewDataColumn.CellTemplate >
<DataTemplate>
<TextBlock Text=”{Binding Budjet}” />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<telerik:RadNumericUpDown Loaded=”Editor_Loaded” Maximum=”10000″ UpdateValueEvent=”PropertyChanged”
Value=”{Binding Budjet, Mode=TwoWay, UpdateSourceTrigger=Explicit}” />
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

<telerik:GridViewDataColumn DataMemberBinding=”{Binding totalcalls}” Header=”Total Calls” Width=”.1*” IsReadOnly=”True” />
<telerik:GridViewDataColumn DataMemberBinding=”{Binding totalleads}” Header=”Total Leads”  Width=”.1*” IsReadOnly=”True” />
<telerik:GridViewDataColumn DataMemberBinding=”{Binding costpercall}” Header=”Cost/Call”  DataFormatString=”{}{0:c}” Width=”.1*” IsReadOnly=”True” />
<telerik:GridViewDataColumn DataMemberBinding=”{Binding totalsale}” Header=”Total Sale”  DataFormatString=”{}{0:c}” Width=”.1*” IsReadOnly=”True”>
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:SumFunction SourceField=”totalsale” ResultFormatString=”{}{0:c}”></telerik:SumFunction>

</telerik:GridViewDataColumn.AggregateFunctions>
<telerik:GridViewDataColumn.FooterCellStyle>
<Style TargetType=”telerik:GridViewFooterCell” >
<Setter Property=”FontWeight” Value=”Bold”  ></Setter>
<Setter Property=”BorderThickness” Value=”0,1,0,0″ />
</Style>

</telerik:GridViewDataColumn.FooterCellStyle>

</telerik:GridViewDataColumn>
<telerik:GridViewDataColumn DataMemberBinding=”{Binding revenue}” Header=”ROI”  DataFormatString=”{}{0:c}” Width=”.1*” IsReadOnly=”True” >

<telerik:GridViewDataColumn.AggregateFunctions>

<telerik:SumFunction SourceField=”revenue”    ResultFormatString=”{}{0:c}”></telerik:SumFunction>

</telerik:GridViewDataColumn.AggregateFunctions>
<telerik:GridViewDataColumn.FooterCellStyle>
<Style TargetType=”telerik:GridViewFooterCell”>
<Setter Property=”FontWeight” Value=”Bold” ></Setter>
<Setter Property=”BorderThickness” Value=”0,1,0,0″ />
</Style>

</telerik:GridViewDataColumn.FooterCellStyle>
</telerik:GridViewDataColumn>

</telerik:RadGridView.Columns>

<i:Interaction.Behaviors>
<local:EmptyDataTemplateBehavior>
<local:EmptyDataTemplateBehavior.EmptyDataTemplate>
<DataTemplate>
<TextBlock Text=”No results found!” Foreground=”red”  HorizontalAlignment=”Center”  VerticalAlignment=”Center” />
</DataTemplate>
</local:EmptyDataTemplateBehavior.EmptyDataTemplate>
</local:EmptyDataTemplateBehavior>
</i:Interaction.Behaviors>
</telerik:RadGridView>

 

 

  //This Function Return color give this function

public Color FromHex(string hex)
{
string v = hex.TrimStart(‘#’);
if (v.Length > 8) //replace with number 8
return Colors.Blue;
if (v.Length == 6)
v = “FF” + v; // Add Alpha value
if (v.Length < 6) //replace with number 6
v = “FF” + v;
while (v.Length < 8) //replace with number 8
v += “0”;
Color c = new Color();
c.A = (byte)System.Convert.ToInt32(v.Substring(0, 2), 16);
c.R = (byte)System.Convert.ToInt32(v.Substring(2, 2), 16);
c.G = (byte)System.Convert.ToInt32(v.Substring(4, 2), 16);
c.B = (byte)System.Convert.ToInt32(v.Substring(6, 2), 16);
return c;
}

 

//Rad_loaded Entent

 

private void grdCompaignList_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if (e.Row.DataContext != null)
{
campaign cbf = e.Row.DataContext as campaign;
if (cbf != null)
{
if (cbf.revenue < 0)
{

e.Row.Cells[7].SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#E72727”)));
}
//else {
//    e.Row.Cells[7].SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#088A4B”)));

//}

}
// else if (cbf.Calldatetime > DateTime.Now && cbf.Calldatetime < DateTime.Now.AddMinutes(30))
// {
//call back time in half hour
//  e.Row.SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#a4d6ff”)));
//}
//else if (cbf.Calldatetime < DateTime.Now)
//{
//call back time passed
//  e.Row.SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#E98A88”)));
//}
}
}

 

conditional-formatting-rows-in-radgridview.

http://blogs.telerik.com/blogs/posts/08-11-21/conditional-formatting-rows-in-radgridview.aspx

Advertisements
 
Leave a comment

Posted by on December 19, 2011 in Silverlight

 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: