RadGridView Add CellStyleSelector to dynamic colums

2 posts, 0 answers
  1. Mark
    Mark avatar
    50 posts
    Member since:
    Dec 2010

    Posted 07 Oct 2015 Link to this post

     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.

     

     

     

     

  2. Mark
    Mark avatar
    50 posts
    Member since:
    Dec 2010

    Posted 07 Oct 2015 in reply to Mark Link to this post

    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(); 

     

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top