Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2006

Tip: Looking for answers? Try searching our database.

Able To Have Generic User Controls in .net 2.0? / Winforms and Generics

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter  Nofelt - 27 Feb 2006 23:03 GMT
Hey All,

I'm wondering if I'm able to have create generic user controls in .net
2.0 much like one can create generic classes.

I would like to do this so that I can handle a set a types derived from
the same base type within a user control

Consider the following scenario:

* I create a base user control that contains a generic <ItemType>.
  * Note: there exists a where clause referencing a specific base type
(see code below).
  * Displays info associated to base class via specific methods.
* I derive another user control from this base control with a concrete
type
  * Derived control now displays info associated with the concrete
type.

Please let me know the following:

* If this is possible
* If you have done this, what caveats exist
* Point me to any online references about the topic

Cheers,
peter

Code
=============================
== BASE USER CONTROL ==
namespace GenericWinformTest
{
   public partial class UserControl1<ItemType>  : UserControl
   where ItemType : Animal, new()
   {
       internal Animal itype;
       public UserControl1()
       {

           InitializeComponent();
           itype = new ItemType();
       }

       private void talk_Click(object sender, EventArgs e)
       {
           this.textBox1.Text = itype.talk();
           //talk
       }
   }//end class
}//end namespace

== Derived user control ==
namespace GenericWinformTest
{
   public partial class dog : UserControl1<type.Dog>
   {
       public dog()
       {

           InitializeComponent();
           
       }
   }//end class
}//end namespace
Bob Powell [MVP] - 28 Feb 2006 12:27 GMT
Shades of ATL there...;-)

Personally I thing ATL was an absolutely horrible thing. I sincerely hope it
never comes back.

> Hey All,
>
[quoted text clipped - 61 lines]
>    }//end class
> }//end namespace

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.