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

RadGridView custom control

10 Answers 276 Views
GridView
This is a migrated thread and some comments may be shown as answers.
AnnS
Top achievements
Rank 1
AnnS asked on 16 Apr 2010, 04:22 PM
I need to write a custom control for the RadGridView which would contain a button to export the records to an Excel.
Making use of the .ToHTML method this is possible. But since the same functionality is to be replicated across the application may be a custom control would be appropriate.
Does anyone has any sample to head start on creating a custom control for RadGridView.

10 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 19 Apr 2010, 07:05 AM
Hello,

Why not just use UserControl?

Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
AnnS
Top achievements
Rank 1
answered on 19 Apr 2010, 02:32 PM
I wanted this control to be custom control as it would support custom styling when re-used.
Also I wanted to make use of the strong binding that the grid view supports.


0
AnnS
Top achievements
Rank 1
answered on 20 Apr 2010, 06:55 PM
Below is the solution with the style but the style is not picked up. Is there a reason. Also if I derive i"SampleControl"  from "Control" everything works fine. (Style is defined in "Themes/genetic.xaml")

 public class SampleControl : RadGridView 
    { 
        static SampleControl() 
        { 
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SampleControl), new FrameworkPropertyMetadata(typeof(SampleControl))); 
        } 

 
[assembly: ThemeInfo( 
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 
    //(used if a resource is not found in the page,  
    // or application resource dictionaries) 
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 
    //(used if a resource is not found in the page,  
    // app, or any theme specific resource dictionaries) 
)] 

If anyone can respond that would be great help as we are transitioning from planning to execution stage.

Thank you


0
AnnS
Top achievements
Rank 1
answered on 21 Apr 2010, 03:49 PM
Can anyone answer this.
0
Accepted
Stefan Dobrev
Telerik team
answered on 23 Apr 2010, 01:01 PM
Hi AnnS,

Internally we are setting the DefaultStyleKey in Initialized method in order for our teams to work correctly. This is the reason why your code is not working.

Have you considered a custom style for the grid instead of deriving from it? In this custom style you can add an attached behavior which adds the button for exporting. Here is a blog post which illustrates how to implement similar functionality with a button in the header.

Greetings,
Stefan Dobrev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
AnnS
Top achievements
Rank 1
answered on 23 Apr 2010, 10:24 PM
Thank You Stefan. That helps

0
Selvakumar Savarimuthu
Top achievements
Rank 1
answered on 25 Jan 2011, 09:07 AM
Hi 

    I need to build custom control inheriting from RadGridView (WPF). I need to set the defaultstylekey for the custom Grid for lots of functalities to be done over the radgridview control.

    I have used below code snippet to override the OnInitialized.

protected

 

 

override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
DefaultStyleKeyProperty.OverrideMetadata(
typeof(iGrid),new FrameworkPropertyMetadata(typeof(iGrid)));
}

    But my style's applied in RadGridView Xaml's is not gettng applied.

I have changed radgrid's template , scrollview template, etc.. it need to be resembled.. and those xaml's are routed in Generic.Xaml.

 

0
Nedyalko Nikolov
Telerik team
answered on 28 Jan 2011, 08:13 AM
Hello Selvakumar Savarimuthu,

Do you have a static constructor that overrides DefaultStyleKey property? If this doesn't help I need a sample project which I can debug on my side to see what's going on.
Thank you in advance.

P.S. You have to open a separate support ticket in order to be able to attach files.

Greetings,
Nedyalko Nikolov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Thomas
Top achievements
Rank 1
answered on 05 Feb 2013, 05:06 PM
Hi,

currently i try to adapt my program from Q1 2011 to Q3 2012. now i've got the exact same problem (style does not load anymore) with my derived radgridview. i am calling 
DefaultStyleKeyProperty.OverrideMetadata(typeof(xxx), new FrameworkPropertyMetadata(typeof(xxx)));
from my static constructor.

Could anyone please help me?

Best Regards,
Thomas
0
Nedyalko Nikolov
Telerik team
answered on 06 Feb 2013, 08:06 AM
Hello,

We've added some new features to our theme mechanism (like possibility to build assemblies with no xaml - in order to get smaller libraries (dlls)). Generally the principles are the same you should have similar code in your static constructor and OnInitialized() method:

static RadGridView()
{
    DefaultStyleKeyProperty.OverrideMetadata(typeof(RadGridView), new FrameworkPropertyMetadata(typeof(RadGridView)));
}
  
protected override void OnInitialized(EventArgs e)
{
    base.OnInitialized(e);
 
    Telerik.Windows.Controls.StyleManager.SetDefaultStyleKey(this, typeof(RadGridView));
}

If this does not help could you please send me a small sample project (in a separate support ticket) that I can debug on my side in order to see what is going on?
Thank you in advance.

Greetings,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
AnnS
Top achievements
Rank 1
Answers by
Vlad
Telerik team
AnnS
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Selvakumar Savarimuthu
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or