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

Custom RadGridView containing predefined columns

3 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alexandru
Top achievements
Rank 1
Alexandru asked on 15 Dec 2014, 04:58 PM
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

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 17 Dec 2014, 11:32 AM
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.

 
0
Alexandru
Top achievements
Rank 1
answered on 26 Feb 2015, 04:19 PM
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
0
Stefan
Telerik team
answered on 27 Feb 2015, 09:21 AM
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.

 
Tags
GridView
Asked by
Alexandru
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Alexandru
Top achievements
Rank 1
Share this question
or