We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Sub classing data grid.

Thread ID:

Created:

Updated:

Platform:

Replies:

2101 Dec 16,2002 11:45 AM Feb 2,2003 05:50 PM Windows Forms 3
loading
Tags: FAQ
Mike P.
Asked On December 16, 2002 11:45 AM

First, let me say I have learned more from the FAQ on this site than all the other .NET sites put together. Thanks alot. Next... I'm writing a largish Windows Forms app and the number of controls and event handlers is getting large, so, I'd like to better organize things. I thought I would take some of the controls on my main form and create separate classes for them, thus moving the code for the control to another source file and making the potential for reusability higher. All I want to do is create a class that inherits from DataGrid (maybe with a couple of additions of my own). The resulting class doesn't have to be usable from the designer, but it would be nice. I tried a couple solutions to this: I tried creating a User Control. This created a source file that inherited from System.Windows.Forms.UserControl. This, I think, is not quite what I'm looking for because I want my control to be just a DataGrid. I tried creating a component, but this inherits from System.ComponentModel.Component. Is it easiest to just create a simple class that inherits from DataGrid and use all run-time calls to place the grid, size it and configure it? Are there any downsides to this method? Feel free tell me how you would do it. Thanks, mp

Shardool Karnik
Replied On December 17, 2002 12:40 PM

I would look into User Controls .... isn't that the way to go if you dock it ? Btw, you are right about the usefulness of this FAQ, Cheers !!! - DooL > First, let me say I have learned more from the FAQ on this site than all the other .NET sites put together. Thanks alot. > > Next... I'm writing a largish Windows Forms app and the number of controls and event handlers is getting large, so, I'd like to better organize things. > > I thought I would take some of the controls on my main form and create separate classes for them, thus moving the code for the control to another source file and making the potential for reusability higher. > > All I want to do is create a class that inherits from DataGrid (maybe with a couple of additions of my own). The resulting class doesn't have to be usable from the designer, but it would be nice. > > I tried a couple solutions to this: I tried creating a User Control. This created a source file that inherited from System.Windows.Forms.UserControl. This, I think, is not quite what I'm looking for because I want my control to be just a DataGrid. > > I tried creating a component, but this inherits from System.ComponentModel.Component. > > Is it easiest to just create a simple class that inherits from DataGrid and use all run-time calls to place the grid, size it and configure it? > > Are there any downsides to this method? > > Feel free tell me how you would do it. > > Thanks, > > mp

Mike P.
Replied On December 17, 2002 02:25 PM

DooL, Thanks for your reply. I'm not sure, but I would think that creating a user control that just has a single control on it would be inefficient. I would like to hear others opinions on this. Thus far I have gone the simplest route and used #region to organize the large number of event handlers I have in the source file, e.g., I have a region call 'currentSelectionGrid Handlers' that contains all the event handlers for my grid. This logically groups the code and provides a comment about what belongs in each group. This does not, however, help me re-use the code I have created for the grid. mp > I would look into User Controls .... isn't that the way to go if you dock it ? > > Btw, you are right about the usefulness of this FAQ, Cheers !!! > > - DooL >

jim
Replied On February 2, 2003 05:50 PM

I can tell you what I do. I'm posting a question for how to do it better myself! Make a new user control. Open the code view and change where it says: Inherits System.Windows.Forms.UserControl to Inherits System.Windows.Forms.DataGrid Now here's the trick. Compile this. Put a regular data grid on a form with drag and drop. then go into the forms code and change the type form windows.Froms.UserControl to myDataGrid, or whatever you named your class.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;