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

RadGridView Add CellStyleSelector to dynamic colums

1 Answer 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 07 Oct 2015, 05:59 AM

 I am populating a griviews columns from the ViewModel and would now like to reference a complex CellStyleSelector. This is normally reference in XAML using... 

<sel:EventDashboardSelector x:Key="eventDashboardSelector"
NormalStyle="{StaticResource NormalCellStyle}"
CompletedStyle="{StaticResource CompletedStyle}"
OverdueStyle="{StaticResource OverdueStyle}"
DueStyle="{StaticResource DueStyle}"
PendingStyle="{StaticResource PendingStyle}" />

 The style selector class is in ..Code.StyleSelectors.EventdashboardSelector.cs

 This is the MVVM snippet where I create the columns

 

foreach (DateTime oDate in lDates)
                {
                    sUniqueName = string.Format("Event{0}", i);
                    oCol = new GridViewDataColumn();
                    oCol.HeaderCellStyle = HeaderStyle();
                    if (oDate == DateTime.Today)
                    {
                        oCol.HeaderCellStyle = HeaderStyleRed();
                    }
                    oCol.CellStyleSelector = vwDashboard.Resources["eventDashboardSelector"] as StyleSelector; <<<<----This is my attempt to reference the resource
                    oCol.Width = 40;
                    oCol.Header = string.Format("{0}/{1}", oDate.Day, oDate.Month);
                    oCol.UniqueName = sUniqueName;
                    oCol.DataMemberBinding = new System.Windows.Data.Binding(sUniqueName);
                    oCol.HeaderTextAlignment = TextAlignment.Center;
                    oCol.TextAlignment = TextAlignment.Center;
                    ColumnList.Add(oCol);
 
                    i++;
                }

 Your help will be appreciated.

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 08 Oct 2015, 12:25 AM

Resolved

I fixed the problem after investigating this thread.

http://www.telerik.com/forums/conditional-formatting-in-grid

Instead of using a resource I needed to assigning the styleselector directly.

oCol.CellStyleSelector = new Code.StyleSelectors.EventDashboard1Selector(); 

 

Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Share this question
or