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

Storing row colors in database - conditional formatting

1 Answer 24 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 15 Dec 2011, 12:21 AM
I have a requirement to allow users to color code rows in the grid. My first iteration is simply saving the hex value in the database and overriding the SelectStyle per one of your examples. I'm a little concerned about performance as our grids can be quite large. Is there a more efficient way?

public class MyStyleSelector : StyleSelector
{
    public override Style SelectStyle(object item, DependencyObject container)
    {
 
            var st = new Style(typeof(GridViewRow));
            if (item is MyClass)
            {
                var myClass = item as MyClass;
                if (MyClass.RowColor != null)
                {
                    st.Setters.Add(new Setter(GridViewRow.BackgroundProperty, GetColorFromHex(myClass.RowColor)));
                }
            }
            return st;
        }
 
    }
 
 
    private static SolidColorBrush GetColorFromHex(string myColor)
    {
        return new SolidColorBrush(
            Color.FromArgb(
                Convert.ToByte(myColor.Substring(1, 2), 16),
                Convert.ToByte(myColor.Substring(3, 2), 16),
                Convert.ToByte(myColor.Substring(5, 2), 16),
                Convert.ToByte(myColor.Substring(7, 2), 16)
            )
        );
    }
 
}

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 15 Dec 2011, 08:11 AM
Hello,

 Generally because of the UI virtualization style selectors will be applied only on visible rows. 

Best wishes,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Marc
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or