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

[Solved] Databound row and style

5 Answers 160 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.
Kyle Watson
Top achievements
Rank 1
Kyle Watson asked on 03 Jan 2011, 11:53 PM
How do you change the row style based on the data bound values that exist in the current row? what is the prefferred method to accomplish this task?

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 04 Jan 2011, 07:58 AM
Hello Kyle Watson,

You may take a look at our demos and online documentation for a reference on the approach for achieving the desired result.
 

Best wishes,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Kyle Watson
Top achievements
Rank 1
answered on 04 Jan 2011, 09:37 PM
Thanks this is perfect.
0
Kyle Watson
Top achievements
Rank 1
answered on 09 Jan 2011, 11:12 PM
I have set the example up in my code and have an additional question:

I would like to set the Value of the color to an ARGB value instead of a predefefined color, what is the easieset way to accomplish this task?
0
Maya
Telerik team
answered on 10 Jan 2011, 10:04 AM
Hello Kyle Watson,

You may take a look at this and this articles for further reference on the definition of different colors.

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kyle Watson
Top achievements
Rank 1
answered on 10 Jan 2011, 04:45 PM

Thanks. I ended up with this, thought i'd share.  

Code Behind:

public sealed class GridStyle : StyleSelector
   {
     
       public GridStyle()
       {
       }
       public override Style SelectStyle(object item, DependencyObject container)
       {
             
           if (item is dataitem)
           {
               
               dataitem = item as dataitem;
               if (dataitem.Status == "Unread")
               {
                   Style BackGroundStyle = new Style();
                   Style bgstyle = new Style(typeof(GridViewRow));                   
                   Setter setBackground = new Setter(GridViewRow.BackgroundProperty, new SolidColorBrush( Color.FromArgb(255,255,0,0)  ));
                   bgstyle .Setters.Add(setBackground);
                   return bgstyle ;
               }               
                
           }
           return new Style();
       }
    
   }

 

xaml:

 

 

<UserControl.Resources>
<local:GridStyle x:Key="BgGridStyle"></local:GridStyle>
</UserControl.Resources>
  
<telerik:RadGridView Name="RadGridView" RowStyleSelector="{StaticResource BgGridStyle} /> 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tags
GridView
Asked by
Kyle Watson
Top achievements
Rank 1
Answers by
Maya
Telerik team
Kyle Watson
Top achievements
Rank 1
Share this question
or