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

RadGridview Apply style when item source is a dynamic collection

4 Answers 53 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claudio
Top achievements
Rank 1
Claudio asked on 28 Aug 2013, 06:18 PM
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

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 02 Sep 2013, 11:22 AM
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 >>
0
Claudio
Top achievements
Rank 1
answered on 03 Sep 2013, 06:27 PM
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
0
Dimitrina
Telerik team
answered on 04 Sep 2013, 02:54 PM
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 >>
0
Claudio
Top achievements
Rank 1
answered on 04 Sep 2013, 03:01 PM
Hi Didie,
Thank you for the information, I understand and I'll try to go on that route.

Thank you
Tags
GridView
Asked by
Claudio
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Claudio
Top achievements
Rank 1
Share this question
or