We are using RadGridview to control the presentation of data of social indicators.
The information shown is related to the time (years) and data in relation to grow over time.
The idea is to have a control that is dynamically complete without a fixed pattern, since each indicator has variables per year. Having a fixed model would represent having to change code every time there's a new year.
One solution is implemented to generate an XML file at runtime using isolated storage IsolatedStorageFile andXmlWriterSettings to write to this file.
Once you create the XML file we use StreamReader to read the file and XDocument to bring the file to the application.
To assign the XML file to control RadGridView do as follows:
RadGridView. ItemsSource = xDoc.Descendants ("Tag name of XML file"). ToList ();
Which is of type XDocument xdoc.
Thus we present the XML content in the control RadGridView.
But this has meant that when exporting data RadGridview information exported by like as the XML file source, I mean that in each cell of the exported table contains the structure of the source XML file. And also disables control the choice of filters is RadGridView default.
How we can solve these problems export result and control of filters?
16 Answers, 1 is accepted
You can use my DataTable if you want to work with dynamic types in Silverlight.
Best wishes,Vlad
the Telerik team
Are there any alternatives? What happened to the good old ITypedList, just wondering if you have an internal interface similar to that one? I've heard a lot of good things about Telerik and decided to give it a try, but this is a deal-breaker for us.
Anyone knows of other Silverlight grids that truly support that kind of dynamic data source?
There is no ITypedList in Silverlight.
The DataTable is not related to RadGridView and it is not official Telerik product - it is just a class that I've made to help people with such scenarios.
Vlad
the Telerik team
I have the similar issue regarding the GridView DataColumn. In my case i use to add new column and sometimes my Gridview Column is around 5000 which which makes the application extensively slow. But then i found your suggestion to use the DataTable which now i am trying to use. I am also using a convertor class to get the wrapping text as the Header value how i am going to implement styles with the DataTable?
private
static GridViewDataColumn CreateColumn(KeyValuePair datavalue)
{
return new GridViewDataColumn()
{
IsSortable =
true,
Header = datavalue,
SortMemberPath = datavalue.Key,
IsReadOnly =
false,
HeaderCellStyle =
Application.Current.Resources["WordWrapDataGridThemeHeaderStyle"] as Style,
DataMemberBinding =
new Binding("Data")
{
Converter = _RowIndexConverter,
ConverterParameter = datavalue
}
};
}
Thanks
Manish
Thanks,
Andrew
There are various ways to provide dynamic data for grid cells - you can check for example the blog post I've just posted for more info about IValueConverter for grid columns DataMemberBinding approach.
Greetings,Vlad
the Telerik team
The columns are generated perfectly, but the settings that did to the style of the header columns are completely ignored.
Can you help me?
Thanks!
Can you post more info where you've set this styles? For auto-generated columns this can be achieved using AutoGeneratingColumn event using e.Column.
Best wishes,Vlad
the Telerik team
I'm working with MVVM and therefore would not be feasible to work with the event that you said.
I'm setting the style of the header of the grid HeaderRowStyle property, which is bind with a defined style as a StaticResource. See the snippet below:
<
UserControl.Resources
>
<
Style
x:Key
=
"HeaderStyle"
TargetType
=
"GridView:GridViewHeaderRow"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
<
Setter
Property
=
"Background"
Value
=
"Yellow"
/>
</
Style
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadGridView
x:Name
=
"radGrid"
ItemsSource
=
"{Binding GridItemsSource}"
RowIndicatorVisibility
=
"Collapsed"
IsReadOnly
=
"True"
ShowGroupPanel
=
"False"
AutoGenerateColumns
=
"True"
CanUserFreezeColumns
=
"False"
CanUserResizeColumns
=
"False"
HeaderRowStyle
=
"{StaticResource HeaderStyle}"
/>
</
Grid
>
In the design time, the style is applied, but at runtime the style is ignored for columns that are generated dynamically, as you can see in the picture attached.
I'm waiting your reply.
Thanks,
Bruno
If you want to change the appearance of the columns' headers, you may define an implicit style targeted at GridViewHeaderCell.
Include such style in the UserControl's Resource collection, please refer to the following:
<
UserControl.Resources
>
<
Style
x:Key
=
"HeaderStyle"
TargetType
=
"telerik:GridViewHeaderRow"
>
<
Setter
Property
=
"Background"
Value
=
"Yellow"
/>
</
Style
>
<
Style
TargetType
=
"telerik:GridViewHeaderCell"
>
<
Setter
Property
=
"Foreground"
Value
=
"Red"
/>
<
Setter
Property
=
"Background"
Value
=
"Yellow"
/>
</
Style
>
</
UserControl.Resources
>
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
DataContext
=
"{Binding Source={StaticResource SampleDataSource}}"
>
<
telerik:RadGridView
HeaderRowStyle
=
"{StaticResource HeaderStyle}"
ItemsSource
=
"{Binding Collection}"
Margin
=
"0,0,0,112"
/>
</
Grid
>
</
UserControl
>
Such implict style will be applied to all columns in RadGridView either declaratively created or dynamically added.
Kind regards,
Vanya Pavlova
the Telerik team
thanks,
Bruno
Hi Vlad,
Thanks for pointing me to the examples! I see few issues with that approach, though. In your example, there is a dummy "Id" property which you use for creating a binding. In true dynamic data, however, there will be no properties, just rows and columns. So I've modified your example in the following way - now we bind to the row itself and store a reference to the column in the converter:
var converter = new RamValueConverter(); var tableView = RamDemoTable.GetInstance(); // RamTableView: IList<ITableRow> foreach (var column in tableView.Columns) { radGrid.Columns.Add(new GridViewDataColumn() { DataType = column.ItemType, Header = column.Name, DataMemberBinding = new Binding("") { Converter = converter, ConverterParameter = column, }, }); } radGrid.ItemsSource = tableView.Rows;
It "kind of" works, but of course it looks more like a workaround than a proper solution. For instance, you can't sort rows anymore since ITableRow does not implement IComparable for obvious reasons. Speaking about sortings - my data source has highly optimized sorting routines, is there a way to tell grid to use them instead of your generic built-in sorting?
Also, since you are creating demo apps demonstrating the usage of dynamic data, may I suggest a better example than just showing 300 int columns? Show 300 columns of random types.
Thanks a lot for helping me out!
Regards,
Andrew
I am not quite sure why the foreground is not applied, do you have defined any implict style targeted at TextBlock? Could you please elaborate a little bit more?
Also you may send us in a new support ticket small repro where we can see what happens in your case.
Vanya Pavlova
the Telerik team
Problem solved! Thanks a lot.
http://www.syncfusion.com/products/user-interface-edition/silverlight/grid/gridcontrol
for binding.
The solution (probably not ideal) which I came up with was to add two properties to my viewmodel: datarows and datacolumns.
I had to create an attached property to put on the RadGridView which my viewmodel uses to inform the grid that columns have
changed.
The event handler for the change will clear out all of the Columns first and then walk through the collection of our column
objects and create the columns dynamically using databinding for pointing at the correct element in the datarows.
gridCol.DataMemberBinding = new Binding(string.Format("[{0}]", col.ColumnID));
This meant adding a [] operator to my datarow object in a shared class (to share between the RIA
server and the SL code).
Now because [] isn't the fastest, the most common columns (which we know will be there the majority
of the time): those were added as explicit properties to the datarow object and the respective binding
was set for those fields directly rather than using the [] operator.
Now it would have been a LOT easier of RIA would support List<Dictionary>, but that' another matter entirely.
We love Telerik over here and hope this might help you find a way to retain usage of the RadGridView.