RadGridView custom control

11 posts, 1 answers
  1. AnnS
    AnnS avatar
    8 posts
    Member since:
    Feb 2010

    Posted 16 Apr 2010 Link to this post

    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.
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 19 Apr 2010 Link to this post

    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.
  3. AnnS
    AnnS avatar
    8 posts
    Member since:
    Feb 2010

    Posted 19 Apr 2010 Link to this post

    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.


  4. AnnS
    AnnS avatar
    8 posts
    Member since:
    Feb 2010

    Posted 20 Apr 2010 Link to this post

    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


  5. AnnS
    AnnS avatar
    8 posts
    Member since:
    Feb 2010

    Posted 21 Apr 2010 Link to this post

    Can anyone answer this.
  6. Answer
    Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 23 Apr 2010 Link to this post

    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.
  7. AnnS
    AnnS avatar
    8 posts
    Member since:
    Feb 2010

    Posted 23 Apr 2010 Link to this post

    Thank You Stefan. That helps

  8. Selvakumar Savarimuthu
    Selvakumar Savarimuthu avatar
    23 posts
    Member since:
    Sep 2012

    Posted 25 Jan 2011 Link to this post

    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.

     

  9. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 28 Jan 2011 Link to this post

    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>>
  10. Thomas
    Thomas avatar
    28 posts
    Member since:
    Jun 2010

    Posted 05 Feb 2013 Link to this post

    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
  11. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 06 Feb 2013 Link to this post

    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.

Back to Top