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
SK
Shardool Karnik
December 17, 2002 05:40 PM UTC
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
MP
Mike P.
December 17, 2002 07:25 PM UTC
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
>
JI
jim
February 2, 2003 10:50 PM UTC
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.