RadGridview Apply style when item source is a dynamic collection

5 posts, 0 answers
  1. Claudio
    Claudio avatar
    5 posts
    Member since:
    Aug 2013

    Posted 28 Aug 2013 Link to this post

    Hi,
    I tried to find an example on when is necessary to apply some column formating to a Radgridview and the itemsource is a dynamic collection.
    Basically I have a gridview defined:
    <telerik:RadGridView x:Name="PreviewGridCombined" GroupRenderMode="Flat"
    Margin="{StaticResource DefaultDetailGridMargin}" RowIndicatorVisibility="Collapsed"
    CanUserFreezeColumns="False" ItemsSource="{Binding PreviewList}"
    telerikStyles:StyleManager.Theme="Office Black"/>

    The ItemSource declaration is:
    private ObservableCollection<ExpandoObject> _previewList = new ObservableCollection<ExpandoObject>();
    public ObservableCollection<ExpandoObject> PreviewList
    {
    get { return _previewList; }
    set
    {
    _previewList = value;
    NotifyPropertyChanged(() => PreviewList);
    }
    }

    Building the structure for the Dynamic Object:
    public ExpandoObject GetPreviewItem()
    {
        var previewItem = new ExpandoObject();
        ((IDictionary<string, object>)previewItem).Add("Date", null);
     
        foreach (var Item in ColumnItemList)
        {
            ((IDictionary<string, object>)previewItem).Add(Item.PropertyName1, null);
            ((IDictionary<string, object>)previewItem).Add(Item.PropertyName2, null);
            ((IDictionary<string, object>)previewItem).Add(Item.PropertyNameN, null);
        }
     
        return previewItem;
    }

    Filling the List with data:
    public ObservableCollection<ExpandoObject> GeneratePreviewList()
    {
              var previewList = new ObservableCollection<ExpandoObject>();
              foreach (var item in DataItems)
              {
                    dynamic previewItem = GetPreviewItem();
                    ((IDictionary<string, object>)previewItem)["Date"] = item.Date;
     
                    ((IDictionary<string, object>)previewItem)["Property1"] = item.Property1Value;
                    ((IDictionary<string, object>)previewItem)["Property2"] = item.Property2Value;
                    ((IDictionary<string, object>)previewItem)["PropertyN"] = item.PropertyNValue;
     
                    previewList.Add(previewItem);
                }
     
                return previewList;
     
        }

    So far so god on loading that data into the grid (I might be missing some defintions on the sample).
    Now, my problem is how can I format Property1 Column as currency, Property2 Column as Percent, Date Column as Date.

    I really appreciate any help, and sorry if my example is a bit confusing.

    Thank you

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 02 Sep 2013 Link to this post

    Hi,

    As I understand, your bound data is of type Object. In order to set the proper DataType for the columns, you can subscribe for the AutoGeneratingColumn event. When each column is generated you can also assign additional properties (for example the Style property) for it.

    Let me know how this works for you. 

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Claudio
    Claudio avatar
    5 posts
    Member since:
    Aug 2013

    Posted 03 Sep 2013 Link to this post

    Hi Didie, 
    I'm trying to avoid any usage of the code behind, I'm trying to work with style selector and converters.
    If you have any approach on the path please let me know.

    Thank you
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 04 Sep 2013 Link to this post

    Hi,

    Generally in order to apply the Style at column's level,  you will need to somehow access the column after it has been generated. Another approach  would be to apply a style targeting GridViewCell element. This style will be applied for all the GridViewCells though.

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Claudio
    Claudio avatar
    5 posts
    Member since:
    Aug 2013

    Posted 04 Sep 2013 Link to this post

    Hi Didie,
    Thank you for the information, I understand and I'll try to go on that route.

    Thank you
Back to Top
DevCraft banner