Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Custom Control inherited from GroupBox
 

Custom Control inherited from GroupBox

Hello friends!

I'm developing a custom control inherited from GroupBox class. As a inherited group box, I don't know why, but the visual representation of the control is not showed in design time. Instead I get a gray screen with a message "drag controls here...bla bla..." or something else. Until here it's ok, the problem is I have to add a datagridview inside the control and just dragging it from toolbox didn't solve. Trying to solve that, I instantiate the DGV at the custom control New method and I added the control via Me.Controls.Add. In order to access the DGV inside the control, I added a property returning it. All woked well, except the fact that If I click the Columns property (...) button of the datagridview at properties window, I get a error "object reference not set to an instance of an object".

It seems by adding a control via Controls.Add does not actually "create it" at design time.

How can I solve that?

Thank you
Regards,
Guilherme.
  • Moved byeryangMSFTMonday, September 14, 2009 2:57 AM (From:.NET Base Class Library)
  •  
Guilherme Fonseca  Friday, September 11, 2009 2:02 AM
There is no usable designer for controls derived from a control class. You'll need to use a UserControl instead. Dock a GroupBox inside of it, then add whatever controls you need.

Hans Passant.
nobugz  Friday, September 11, 2009 2:21 AM
Did you add a common class or a component ? If you're using a component, you will not get it from toolbox. You can try add a common class and inherit from GroupBox, then you willuse it.
Linux_Web  Friday, September 11, 2009 3:05 AM
I used a common class. Nobugz, I simply can't dock a visible GroupBox to my user control because with the component ready and working, I can't drag any other item inside the groupbox, I can't make any other control be a control of the GroupBox inside my Custom control. How can do it?

thanks for reply.
Guilherme Fonseca  Friday, September 11, 2009 10:25 AM
Not quite sure what you mean. If you need to add additional controls after putting your custom control on a form, you'll need a designer derived from ParentControlDesigner. Ask questions about that in the Windows Forms Designer forum. If you simply derive your own class from GroupBox, it will act like a GroupBox at design time without any additional work needed. But without the ability to add controls to it to make a composite control like UserControl.

Hans Passant.
nobugz  Friday, September 11, 2009 11:21 AM

You can use google to search for other answers

Custom Search

More Threads

• How do I add scrolling to a derived Panel?
• XML Mapper
• Get the ExternaProvider Control Refrence in the UITypeEditor
• Using interface as a property type?
• I want to have a WinForm screen like a IE screen with vertical scrollbar, with Form1.Size(1036,780) more than Max Height.
• Custom ToolStripRenderer - Display at Design Time?
• RemoveItem and SetItem in the collection editor are not firing
• datagridview pause filter while editing
• (URGENT)
• Distribution Requirements