Hi,
I'd like to ask if it is possible to change the captions of the measures/dimensions generated automatically by a flatdatasource (based on an IEnumerable)? So if the flatDataSource.ItemsSource is set to an IEnumerable and the captions are like "PRDGRP" and "ST_DATE" by default, then I'd like to display them in the dataselector as "Product Group" and "Start date". Is it possible to change the captions of the items in the data selector?
Thanks and best regards,
Tamas
Hi Tamas,
You can decorate the properties of your business objects’ class with DisplayAttribute and set its Name property and this value will be displayed in the UI of the pivot grid.
[DisplayAttribute(Name = "Product Group")]
public string ProductGroup
{
get;
set;
}
Note that there is an option also to set display format for the measures. In this case you set DisplayFormatAttribute:
[DisplayFormat(DataFormatString = "{0:C2}")]
public double Cost
If you want to do that within XAML you have to add a new CubeMetadata object to FlatDataSource.CubeSettings collection and then have to add DimensionMetadata object for each property:
<!—Overrides the default meta attributes -->
<FlatData:FlatDataSource.CubesSettings>
<FlatData:CubeMetadata DataTypeFullName="[Your data type full name]" DisplayName="[The UI name of the cube]">
<FlatData:DimensionMetadata SourcePropertyName="ProductGroup" DisplayName="Product Group"/>
</FlatData:CubeMetadata>
</FlatData:FlatDataSource.CubesSettings>
I hope that covers your needs.
Regards.
PPilev.
Hi Plamen,
Since the business objects are not known during design time, I would need this during runtime. Here is my code, but it does not work:
public FlatDataSource CreateDataSource(List<Dictionary<object, object>> list, ObservableCollection<string> texts) { FlatDataSource flatDataSource = new FlatDataSource();
// this creates an IEnumerable from the list<dictionary<object,object>>
flatData = DataSourceCreator.ToDataSource(list); flatDataSource.ItemsSource = flatData; CubeMetadata csettings = new CubeMetadata { DataTypeFullName = flatData.GetType().ToString(), DisplayName = "DisplayNameXYZ" };
// go through the first dictionary to get the property names from the keys
int i = 0; foreach (KeyValuePair<object, object> pair in list[0]) { DimensionMetadata dm = new DimensionMetadata(); dm.DisplayName = texts[i]; dm.SourcePropertyName = pair.Key.ToString(); csettings.DimensionSettings.Add(dm); i++; } flatDataSource.CubesSettings.Add(csettings);
...
The name of the cube is still equal to the name of the type and the texts are still equal to the field names. What do I do wrong?
Many thanks and best regards,
Tamás