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

Creating and Applying cell style selector dynamically

1 Answer 127 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
preeti asked on 15 Mar 2011, 11:17 AM
Hi ,
I need to dynamically create and apply cell style selector  to a perticualr column. Can you help me with this?
    void ViewModel_delApplyRuleEvent()
            Dictionary<string, ColorRuleConfig> dictColorRuleConfig = viewmodelobj.dictColorRuleConfig;
            if (dictColorRuleConfig != null && dictColorRuleConfig.Count > 0)
                foreach (var item in dictColorRuleConfig)
                    GridViewColumn col = dataGrid1.Columns[item.Value.ColumnName];
                    Color backcolor = new Color();
                    backcolor.A = 255;
                    backcolor.R = byte.Parse(item.Value.RuleBackColor.Substring(0, 2), NumberStyles.HexNumber);
                    backcolor.G = byte.Parse(item.Value.RuleBackColor.Substring(2, 2), NumberStyles.HexNumber);
                    backcolor.B = byte.Parse(item.Value.RuleBackColor.Substring(4, 2), NumberStyles.HexNumber);
                    SolidColorBrush BrushBackColor = new SolidColorBrush(backcolor);
                    Color forecolor = new Color();
                    forecolor.A = 255;
                    forecolor.R = byte.Parse(item.Value.RuleForeColor.Substring(0, 2), NumberStyles.HexNumber);
                    forecolor.G = byte.Parse(item.Value.RuleForeColor.Substring(2, 2), NumberStyles.HexNumber);
                    forecolor.B = byte.Parse(item.Value.RuleForeColor.Substring(4, 2), NumberStyles.HexNumber);
                    SolidColorBrush BrushForeColor = new SolidColorBrush(forecolor);
                    string[] strarr = item.Value.RuleExpression.Split(new char[] { '=' });
                    string strColName = strarr[0];
                    string strColVal = strarr[1];
                    Tuple<SolidColorBrush, SolidColorBrush> ColorsProperty = Tuple.Create<SolidColorBrush, SolidColorBrush>(BrushBackColor, BrushForeColor);
                    Func<string, bool> FuncProperty= (s) => { if (s == strColVal) return true; return false; };
                    Style st = new Style(typeof(GridViewCell));
                    st.Setters.Add(new Setter(GridViewCell.BackgroundProperty, ColorsProperty.Item1));
                    st.Setters.Add(new Setter(GridViewCell.ForegroundProperty, ColorsProperty.Item2));
                    this.Resources.Add(item.Value.ColumnName + "CellStyle", st);
//***********************i am stuck up here******************************************
                    StyleSelector sc = new StyleSelector();
                    dataGrid1.Columns[item.Value.ColumnName].CellStyleSelector = sc;

1 Answer, 1 is accepted

Sort by
Ivan Ivanov
Telerik team
answered on 15 Mar 2011, 02:12 PM
Hello preeti,

I have already answered to this inquiry in this thread. In order to achieve consistent and constructive dialogue, I would kindly ask you to continue any further communication in your initial thread.

Ivan Ivanov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Asked by
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question