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

Unable to add Columns to RadGridView after being added as a FrameworkElementFactory

3 Answers 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rod Yager
Top achievements
Rank 1
Rod Yager asked on 18 Jul 2011, 05:14 PM
I have a RadGridView that is part of a datatemplate that I am creating at runtime via c#. All is good if I AutoGenerate the columns. If I try to create the GridViewDataColumns I have no way of adding them. Seems the Columns property is not exposed as a dependency property. Can you please look into this and suggest a work around or possible solution? In my example, RadGridView.Columns does not appear to be accessible.
FrameworkElementFactory radGridView = new FrameworkElementFactory(typeof(RadGridView));
radGridView.SetValue(RadGridView.ShowGroupPanelProperty,false);
radGridView.SetValue(RadGridView.ShowInsertRowProperty, false);
 
Telerik.Windows.Controls.GridViewColumnCollection colCollection = new Telerik.Windows.Controls.GridViewColumnCollection();
 
GridViewDataColumn dc = new GridViewDataColumn();
dc.Header = "test"
 
colCollection.Add(dc);
radGridView.SetValue(RadGridView.Columns,colCollection);

3 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 22 Jul 2011, 07:24 AM
Hi Rod Yager,

Please, excuse for the late answer. Unfortunately you are hitting a framework limitation, so there is little to do, in order to make this approach work. The solution that comes to my mind is to customize the FrameworkElementFactory, setting the needed DependencyProperties and the set it as a visual tree of the respective template. On parent element's Loaded event, you may seek for the generated RadGridView in its template and add the columns. Please, let me know whether this approach meets your requirements.

Kind regards,
Ivan Ivanov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Rod Yager
Top achievements
Rank 1
answered on 22 Jul 2011, 07:39 PM
A framework limitation? How so? In .NET or in Telerik's construction of the GridView control? I am not really sure what you are suggesting for a solution.

Rod
0
Ivan Ivanov
Telerik team
answered on 25 Jul 2011, 10:05 AM
Hello Rod Yager,

Mentioning limitations, I have meant the fact that one is not allowed to set non-dependency properties in FrameworkElementFactory's definition. Since "Columns" is not a dependency property, the approach you have described won't be valid. Alternatively you may add these columns at runtime, finding the RadGridView in the visual tree, or subscribing to an appropriate event. I have prepared an example project for you. It is attached for your reference.

All the best,
Ivan Ivanov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
Rod Yager
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Rod Yager
Top achievements
Rank 1
Share this question
or