all groups > dotnet windows forms > april 2007 >
You're in the

dotnet windows forms

group:

DataGridView inheritance


DataGridView inheritance Nick Locke
4/30/2007 9:46:41 PM
dotnet windows forms: I have just found that there is a feature in VS .NET which deliberately
stops me making a DGV "protected" in an ancestor class and then modifying
its properties in inherited classes. I can see why this problematic for MS
and therefore why it has not been implemented. However, I could do with a
suggestion on how best to move forwards with what I need to do.....

I have an ancestor UserControl which contains a single DGV and lots of
methods/properties to allow me to "talk" with that DGV from a containing
form.

I then need around 30 UserControls inherited from that ancestor. They all
need to offer the same methods/properties, but will need different data
connections from their instance of the DGV. They will also need different
columns displayed, with different headings and so on.

I could obviously bin the OO approach altogether and just copy my control 30
times - but I am fearful of then needing to make every change 30 times in
the future.

Suggestions please!

Thanks, Nick.

Re: DataGridView inheritance Nick Locke
4/30/2007 9:59:54 PM
Thinking of one way for myself (maybe). Would it make sense to "paint" each
DGV separately (eg on a form)and then paste the code from the designer into
my inherited class somewhere?

[quoted text, click to view]

Re: DataGridView inheritance Kevin Spencer
5/1/2007 12:00:00 AM
You don't have to inherit a DataGridView to create a new class. You can
create a container class that implements and exposes a DataGridView.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

[quoted text, click to view]

Re: DataGridView inheritance Nick Locke
5/1/2007 9:38:04 PM
[quoted text, click to view]

Kevin, if I am understanding correctly, you are saying that I don't need to
create a User Control, put a DGV on it and then use that as an ancestor
class for all of my objects. Rather, I think you are suggesting that I
create a customised DGV (encapsulating all of my functionality) and then I
just plonk one of those onto each of my target user controls and/or forms.
Am I on the right wavelength?

So, to "create a container class that implements and exposes a
DataGridView", I was hoping that when I did this:

Public Class CustomDGV
Implements System.Windows.Forms.?????

End Class

I would just be able to implement a DGV like that. I am showing my
ignorance here, but need a bit more of a pointer.

Thanks,

Nick


Re: DataGridView inheritance Nick Locke
5/1/2007 9:54:36 PM
Have I answered my own question - is it just:

Public Class CustomDGV

Inherits System.Windows.Forms.DataGridView

End Class

Thanks?!

[quoted text, click to view]

Re: DataGridView inheritance Kevin Spencer
5/2/2007 7:24:27 AM
That is one solution. The other is to create a class that implements and
exposes a DataGridView, such as the following (forgive my C#):

public class DataGridViewContainer : UserControl
{
private DataGridView _View;

public int ViewWidth
{
get { return _View.Width; }
set { _View.Width = value; }
}

public DataGridView View { get { return _View; } }
// etc.
}

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

[quoted text, click to view]

Re: DataGridView inheritance Nick Locke
5/2/2007 8:03:36 PM
[quoted text, click to view]


[quoted text, click to view]

Thanks Kevin, that certainly does help. Any views (from Kevin or anyone),
whether there are reasons to choose one approach over the other (hidden
gotchas, etc)?

Thanks

Re: DataGridView inheritance Kevin Spencer
5/3/2007 6:44:57 AM
When you implement a DataGridView rather than inheriting it, you have more
control over what is exposed and what is not. That's about the only
advantage I can think of.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

[quoted text, click to view]

Re: DataGridView inheritance Nick Locke
5/3/2007 9:51:51 PM
That helps. Kevin, thanks for all of your help with this.

Nick

[quoted text, click to view]

AddThis Social Bookmark Button