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

RadGridView dinamic columns

16 Answers 321 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Antonio
Top achievements
Rank 1
Antonio asked on 01 Mar 2011, 01:11 AM

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

Sort by
0
Vlad
Telerik team
answered on 02 Mar 2011, 08:29 AM
Hello,

 You can use my DataTable if you want to work with dynamic types in Silverlight. 

Best wishes,
Vlad
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Andrew
Top achievements
Rank 1
answered on 09 Mar 2011, 07:40 PM
Is it really the only way to bind dynamic data to a Telerik grid? We work with massive amounts of data (could be thousands of columns) which often changes at runtime (columns are added/deleted, tables are pivoted, etc) so creating a brand new type whenever table structure changes doesn't sound like a really good idea. 

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?
0
Vlad
Telerik team
answered on 10 Mar 2011, 08:14 AM
Hello,

 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. 

All the best,
Vlad
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Manish Kumar
Top achievements
Rank 1
answered on 10 Mar 2011, 12:19 PM
Hi

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

0
Andrew
Top achievements
Rank 1
answered on 10 Mar 2011, 05:09 PM
Vlad - yes I understand that there is no ITypedList in SL and that your DataTable is merely a helper. My question, however, was whether it is possible to bind dynamic data to radGridView in a more natural form (perhaps using some internal interfaces?) or should I not waste time with telerik's grid? I figured that instead of reflecting radGridView's code I'd just ask the developers :) This seems like a popular feature request.

Thanks,
Andrew
0
Vlad
Telerik team
answered on 10 Mar 2011, 05:18 PM
Hi 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
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Bruno
Top achievements
Rank 1
answered on 10 Mar 2011, 09:47 PM
Hi Vlad, I'm having trouble changing the style of header of a grid that has generated columns dynamically through the datatable component you developed. 

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!
0
Vlad
Telerik team
answered on 11 Mar 2011, 08:23 AM
Hi,

 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
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Bruno
Top achievements
Rank 1
answered on 11 Mar 2011, 01:32 PM
Hi Vlad, thanks for your reply.

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

0
Vanya Pavlova
Telerik team
answered on 14 Mar 2011, 12:50 PM
Hi Antonio,

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
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Bruno
Top achievements
Rank 1
answered on 14 Mar 2011, 06:10 PM
Thanks for your reply Vanya. This works for the background color of the header, but doesn't for the forecolor. Do you know why this happens?


thanks,
Bruno
0
Andrew
Top achievements
Rank 1
answered on 14 Mar 2011, 07:32 PM
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
0
Vanya Pavlova
Telerik team
answered on 16 Mar 2011, 05:38 PM
Hi Bruno,

 
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.

All the best,
Vanya Pavlova
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Bruno
Top achievements
Rank 1
answered on 16 Mar 2011, 05:51 PM
Exactly Vanya, the problem was a style that we defined.

Problem solved! Thanks a lot.
0
Andrew
Top achievements
Rank 1
answered on 22 Mar 2011, 04:05 PM
Do I understand it right that neither you have proper support for dynamic data nor you plan to add it in the future? Overall, I like your product better, but dynamic data support is THE most important feature for us, so we might switch to Syncfusion's grid just because of that, it seems to have virtual mode -

http://www.syncfusion.com/products/user-interface-edition/silverlight/grid/gridcontrol
0
Ken
Top achievements
Rank 1
answered on 22 Mar 2011, 05:54 PM
My company also has dynamic columns which change on the fly and for this reason we cannot have strongly typed objects
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.

 

Tags
GridView
Asked by
Antonio
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Andrew
Top achievements
Rank 1
Manish Kumar
Top achievements
Rank 1
Bruno
Top achievements
Rank 1
Vanya Pavlova
Telerik team
Ken
Top achievements
Rank 1
Share this question
or