RSS

Monthly Archives: December 2011

How to change row color for RadGrid with specified conditions?


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

 
Leave a comment

Posted by on December 19, 2011 in Silverlight

 

Tags: , ,

Change color for RadGrid Rows


hi.

If you want to  change color of RadGrid Rows.Its Simple and Past Below Code on Code Behind after Giving Datasourse

customize Color according to the specific condition or column

//RadGrid RowLoaded Event

private void grduser_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
{
if (e.Row.DataContext != null)
{
callback cbf = e.Row.DataContext as callback;
if (cbf.Status == 2)
{
//callback finished
e.Row.SetValue(BackgroundProperty, new SolidColorBrush(FromHex(“#3c94f3”)));
}
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”)));
}
}
}

//Create  Function which Return Row color
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;
}

 
Leave a comment

Posted by on December 19, 2011 in Silverlight, Uncategorized

 

Tags: , , , , ,