Discussion:
Proper way to inherit from DataGridView control
Pradeep Tapadiya
2006-04-04 19:15:16 UTC
Permalink
NETters,

What is the right way to inherit DataGridView control?

The steps I tried are:

1. Create a user control class - MyDataGridView.
2. Modify MyDataGridView.cs and change the base class from UserControl to
DataGridView

The first problem I ran into is the code will not compile after the change
is made. MyDataGridView.Designer.cs has the following line in
InitializeComponent() method that won't compile:

this.AutoSacleMode = blah...

I commented this line out. However, the next problem I get is I do not see
any display in the designer view.

Can someone enlighten me on what I am missing?

Thank you in advance for your help.

Pradeep
Vince P
2006-04-04 20:18:53 UTC
Permalink
The issue is this.AutoScaleMode is a property that existed in your original
base class but is not in the new base class. So you need to delete that
line.



-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps and
controls [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Pradeep
Tapadiya
Sent: Tuesday, April 04, 2006 14:15
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: [DOTNET-WINFORMS] Proper way to inherit from DataGridView control

NETters,

What is the right way to inherit DataGridView control?

The steps I tried are:

1. Create a user control class - MyDataGridView.
2. Modify MyDataGridView.cs and change the base class from UserControl to
DataGridView

The first problem I ran into is the code will not compile after the change
is made. MyDataGridView.Designer.cs has the following line in
InitializeComponent() method that won't compile:

this.AutoSacleMode = blah...

I commented this line out. However, the next problem I get is I do not see
any display in the designer view.

Can someone enlighten me on what I am missing?

Thank you in advance for your help.

Pradeep
Pradeep Tapadiya
2006-04-04 21:00:49 UTC
Permalink
Vince,

Thank you for your help.

It is obvious that the property is not available on the base class and I
did comment it out. However, from the design perspective, it is a good
practice not to touch *.Designers.cs files. This, coupled with the fact
that I still don't see the DataGridView control in the design mode, are the
reasons that made me wonder if there was a different way to inherit
standard forms controls, especially the DataGridView control.

Appreciate your help.

Pradeep
Vince P
2006-04-04 22:28:32 UTC
Permalink
Pradeep: The auto-updating of the designer.cs file is done as a result of
changes made in the designer.

When changing the Base class of a class, the designer has no idea that you
changed the code text so it wont rescan the class's base and reconcile it
with the members that were already genreated. That sort of change is
beyond the mission of the designer.


I can confirm to you that when you use an existing control as a base class
you will not see the control in the designer anymore.

-----Original Message-----
From: Discussion forum for developers using Windows Forms to build apps and
controls [mailto:DOTNET-***@DISCUSS.DEVELOP.COM] On Behalf Of Pradeep
Tapadiya
Sent: Tuesday, April 04, 2006 16:01
To: DOTNET-***@DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-WINFORMS] Proper way to inherit from DataGridView
control

Vince,

Thank you for your help.

It is obvious that the property is not available on the base class and I did
comment it out. However, from the design perspective, it is a good practice
not to touch *.Designers.cs files. This, coupled with the fact that I still
don't see the DataGridView control in the design mode, are the reasons that
made me wonder if there was a different way to inherit standard forms
controls, especially the DataGridView control.

Appreciate your help.

Pradeep

Loading...