DataGridView in child form - c#

I have a base windows form containing a DataGridView. The DataGridView has the modifier set to Protected.
When creating a descendant form the DataGridView properties cannot be changed. They are greyed out. The events are also not editable through the Properties panel. This would all be in the Designview.
You can however add an event handler to, for example, DoubleClick from inseide the code editor.
Why can this not be done from inside the designer?
I have other controls on the base form also set to Protected which can be altered from Design view in the child form.

To modify a control from baseform in inherited forms or usercontrols we should change controls acces modifier property to 'Protected' or 'Public'.
MSDN - https://social.msdn.microsoft.com/Forums/vstudio/en-US/3246a701-cc50-4109-b981-3eea04dacdeb/question-inherited-form-with-control?forum=csharpgeneral
DevExpress - https://www.devexpress.com/Support/Center/Question/Details/A679

Related

(C#) The WinForm designer is constantly generating "SetChildIndex" codes on derived forms. how do i prevent this?

I have a base form with a panel in it. When I inherit in another form, vs constantly adds "SetChildIndex" codes to the designer.cs file. The "btnexcel" control belongs to the base form. I added the others in derived form. How can I prevent these codes from being generated?
It only happens when the Modifiers of the button on the base form is set to protected or public. In this case you can modify the control at design-time in the derived form.
If you are interested to add controls to the panel of the base form, then the panel modifier should be protected or public. Then if you want to prevent modifying the existing children of the panel, set their modifiers to private. In this case, when you select one of those private children in designer in the derived form, a small lock icon appear on top-left of the control which shows you cannot modify it.
To learn more about access modifiers in visual inheritance see:
How to: Inherit Forms Using the Inheritance Picker
Add a button that inheritors of the base form can modify
Add a button that cannot be modified by inheritors of the base form

C# Child Form Inheriting a Control from Parent Form

The way my application is organized is I have a base form and multiple child forms that inherit from it. I also have a button defined as a UI control. I want to add the UI control to the base form so all the child forms can also have that control. However, I don't want to mess with all the individual child forms because the control should be the same for all of them.
What I have done so far:
Added the control to the designer of baseFrom.cs, which in turn created a InitializeComponent() function in the base form that listed all the properties of the control. I have tried calling the InitializeComponent in the base form's constructor but that still does not make the control appear in any of the child forms. What am I missing here?
after you add control to base form you need to build solution and then control will appear in inherited forms

Inherited Control from base Form class not working properly

I have FormBase and MainForm : FormBase.
FormBase Contains a DataGridView dgv. in designer view of FormBase dgv font sizes are fine but in designer view and runtime in MainForm they are default values. why and what should I do??!
The designer for DVG doesn't support designing the control in an inherited form, a limitation of many designers of controls that were added in .NET 2.0. The Font property is an 'ambient' property, it gets the same value as the parent unless you've explicitly selected one (shown in bold in the Properties window). So either set the form's Font property to also change the DGV font or change the Font property of the DGV in the base form.
To clarify my comment: putting UI (together with DataGridView) from BaseForm in custom user control and using it separately on previously inheriting forms will surely fix the font problem.
If your base form is only "container" for commonly used controls (so you don't have to put 3 buttons, datagrid and label on every window) or defines some basic layout - go with custom user control.
Here's decent starting point if you want to explore this topic - Custom User Controls.
Have you tried this approach: http://dotnetengineer.wordpress.com/2008/06/27/visual-inheritance-using-datagridview/

C# Template Forms Get panel in parent form

I have a form that I have created that contains a panel - panel1.
I have then created a template form that inherits the first form.
How can I add something to the panel that I inherited from my template?
You need to set the panel's Modifiers to Protected in the property grid.
Make panel1 visible using protected keyword so it will be visible in your inherited class.

How do I handle drag-and-drop in the designer?

I've created a control, DataGridViewContainer, that fakes partial-line scrolling in a DataGridView - basically it's a panel and a scrollbar and a few event handlers. I'd like to be able to use DataGridViewContainer at design time, dragging a DataGridView onto it to set its .DataGridView property to the dragged control. How do I handle drag-and-drop in the designer?
If you want to be able to drag a datagridview (or any other object in fact), your usercontrol needs to be configured to act as a container,
A simple example a control acting as a container
Alternatively, and what I would reccomend, is that if each container will always contain a single datagridview, just add a datagridview to the usercontrol at design time (the usercontrol designer, not the form containing the control). You can set properties in the usercontrol to expose the relevant properties that you'll need to change.

Categories