Custom RadGridView containing predefined columns

4 posts, 0 answers
  1. Alexandru
    Alexandru avatar
    4 posts
    Member since:
    Apr 2012

    Posted 15 Dec 2014 Link to this post

    hi,

    i am trying to inherit the RadGridView control and create a predefined list of columns.

    if i create the columns in the constructor of the control and using it in a form (winform app), the visual studio designer will add the same columns a second time from the InitializeComponent() method.

    what is the suggested way to do this?

    thank you,
    alez
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 17 Dec 2014 Link to this post

    Hi Alez,

    Thank you for writing.

    I managed to replicate the described case. It is caused by the fact that the Columns collection of RadGridView is a serializible collection, and once you add a column to it, the column will get serialized. Then, when you start the grid, one column will be added from your code, and another from the serialized information in the InitializeComponent. You can easily handle this case, by only adding the column in the derived grid, if you are in design time. For the purpose however, you will have to use the Load event, instead of the constructor:
    public class MyGrid : RadGridView
    {
        protected override void OnLoad(System.Drawing.Size desiredSize)
        {
            base.OnLoad(desiredSize);
     
            if (this.DesignMode)
            {
                GridViewTextBoxColumn col1 = new GridViewTextBoxColumn();
                this.Columns.Add(col1);
            }
        }
    }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Alexandru
    Alexandru avatar
    4 posts
    Member since:
    Apr 2012

    Posted 26 Feb 2015 in reply to Stefan Link to this post

    hi,

    thank you. it worked, with a small observation: the columns has to be created when not in design mode. otherwise it will still crush at design time.

    if (!this.DesignMode)

    is there a better solution?

    alez
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 27 Feb 2015 Link to this post

    Hello Alez,

    Can you please share how can I reproduce the crash you observe?

    I am looking forward to your reply.

    Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top