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

How do I change the CellStyle based on data?

4 Answers 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dan Kinchen
Top achievements
Rank 1
Dan Kinchen asked on 23 Mar 2010, 10:06 PM
Hi, sorry if this is a basic question, but I looked through the first 7 pages worth of posts and didn't see anything exactly like what I am trying to accomplish.  The requirement I have is that I have to display data in a grid but sometimes the data is read only and some times the data is editable on a per-cell basis.  For example take this simple class:

    public class GridDataItem:INotifyPropertyChanged  
    {  
 
        private int _value;  
 
        public int Value  
 
        {  
 
            get { return _value;}  
 
            set { _value = value; OnPropertyChanged("Value");}  
 
        }  
 
        private bool _canEditValue;  
 
        public bool CanEditValue  
        {  
 
            get { return _canEditValue; }  
 
            set { _canEditValue = value; OnPropertyChanged("CanEditValue"); }  
 
        }
        #region INotifyPropertyChanged Members  
 
        public event PropertyChangedEventHandler  PropertyChanged;
        #endregion  
 
        private void OnPropertyChanged(string propName)  
        {  
            if (PropertyChanged != null)  
            {  
                PropertyChanged(thisnew PropertyChangedEventArgs(propName));  
            }  
        }  
    } 

As you can see there is a Value property and a CanEditValue property.  If I load up an ObservableCollection with these and set the ItemsSource of the GridView to the collection, I want to be able to change the CellStyle per row based on the CanEditValue property.  Specifically the user wants to see a white background for read-only data and a beige background for editable data.  Obviously the actual data would have more than one column, but this example shows what I'm trying to accomplish.  I'd prefer to do this through binding rather than programmatically in case the user changes their mind about the specific styling.

Any assistance is appreciated!

Dan

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 24 Mar 2010, 08:32 AM
Hello Dan,

Please check this blog post for more info:
http://blogs.telerik.com/pavelpavlov/posts/09-10-03/adding_additional_power_to_radgridview_for_silverlight_with_attached_behaviors.aspx

All the best,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Dan Kinchen
Top achievements
Rank 1
answered on 24 Mar 2010, 03:02 PM
Thank you!  That's what I needed.  Now if I may trouble you for a follow up question? 

How do I get at the default GridViewCellTemplate using Blend 3?  The blog post you directed me to appears to be using the styles from the 2009 Q3 release, but I'm working with the 2010 Q1 release.  The out-of-the-box GridView in the 2010 Q1 release has very nice styles.  In particular I like the gradients on mouseover and select.  I would like to retain those, but when I copy/paste the style from the blog post, those items go away for the cell that I apply the style to.  It looks odd to have one cell in a row not be highlighted with the gradient brush when I mouse over the row.

EDIT:  I noticed the cell exhibits the same behavior regardless of using the xaml style or the attached behavior method, so I guess the question is how do you retain the mouseover style of the row for the cell even though you've overridden the background of the cell?

0
Accepted
Kalin Milanov
Telerik team
answered on 26 Mar 2010, 10:20 AM
Hi Dan Kinchen,

If you change the background of a cell you are going to loose the MouseOver and Selected states of the row since the cell's content is rendered on top of the row. That being said a possible workaround is to use semi transparent solid colors for the cell's background which will allow for some MouseOver and Selected visuals to pass through, even though they may seem a bit distorted. The final result might look similar to the following online demo:
http://demos.telerik.com/silverlight/#GridView/StylingColumns

I hope this helps.

All the best,
Kalin Milanov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Dan Kinchen
Top achievements
Rank 1
answered on 26 Mar 2010, 02:49 PM
That works perfectly, Kalin!  That's the exact look I was hoping for.

Thank you!!
Tags
GridView
Asked by
Dan Kinchen
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Dan Kinchen
Top achievements
Rank 1
Kalin Milanov
Telerik team
Share this question
or