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

Dynamically Select/Generate GridViewDataColumn

2 Answers 144 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael C
Top achievements
Rank 1
Michael C asked on 07 May 2012, 11:27 PM
Hi
 I would like to create a usercontrol that will allow me have a set a predefined columns within a GridView when bound to a collection of our DataContract classes.   What I would like to see is something on the order of the Data Template Selector... but instead, have that at the GridViewDataColumn level.   Here is an example

[DataContract]
public MyDataClass
{
Public SomeEnum EnumProperty {get;set;}
        Public SomeClass SomeClassProperty {get;set;}
Public int SomeIntProperty {get;set;}
}


Now  lets say I have a List<MyDataClass> and I want to bind this to a RadGridView control and have it auto generate the columns based on some defined logic. I know that I could probably do this in the Auto generate event handler in my code behind though a series of if logic or case staements.  But I would prefer it if there was a way that I can define some sort of a GridViewDataColumnSelector to have it automatically define both of the read only and editor templates. Something on the order of what we have for Data Template or Style Template selector except for the entire GridViewDataColumn.

For the example above.. I would like to auto-generate a Combobox for the Enum to provide a list of Enum possible values.  And for the SomeClass property.. I want to create a ComboBox with a list of values bound to collection of possible values. 

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 May 2012, 06:52 AM
Hello,

 You can use the technique from our demos where the grid columns are bound to a view-model columns using custom attached behavior. You can check this demo for example. The same is available in your local copy our our WPF demos. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael C
Top achievements
Rank 1
answered on 08 May 2012, 12:48 PM
Your solution has some promise. Where migh I find the entire source of this demo?   .
I tried copying down each of the sourcefiles from the examples... but we are missing some pieces... MyColumnsBindingBehavior  is one class I dont see defined in the example code
Tags
GridView
Asked by
Michael C
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Michael C
Top achievements
Rank 1
Share this question
or