C# visually subclass datagridview control VS2005 - c#

Maybe its something stupid, but I'm having a problem with a subclass of a DataGridView Control in VS2005 C#. I know I can subclass from almost anything by doing
public class MyDataGridView : DataGridView
{}
no problem, and I put in some things / elements I want applicable globally. Now, I take this gridview and put into a custom user control that will contain other controls too. So I have something like created by the visual designer. I grab some buttons, label, and my derived "MyDataGridView" on it.
public partial class MyCompoundDGVPlus : UserControl
So, now, I can visually draw, move, change all sorts of settings as needed, no problem.
Now, I want this "MyCompoundDGVPlus" class as the basis for other classes, of which I will manipulate settings specific, but want all to have the same look / feel, and otherwise similar flow, hence the derivations.
I've even set the "modifiers" setting to public, so I SHOULD be able to modify any of the properties of the controls at any derived level. So, now, I create a new subclass of "MyFirstDetailedDGVPlus" derived from "MyCompoundDGVPlus". Ok visually, all the label, button, datagridview appear. However, now I want to specifically define the columns of the datagridview here in this class visually, but its locked. However, the LABEL on the form, I CAN get all the property settings....
What am I missing.

Maybe you should take a look at this post as it seems to do what you are looking for :
DataGridView locked on a inherited UserControl

Related

Add checkbox in the propertygrid

i used PropertyGrid control to display properties on gridview.
i have taken an reference of this link http://www.c-sharpcorner.com/article/using-property-grid-in-c-sharp/
which is showing like this
But i need checkbox just before the property name shown in red mark on check/uncheck for any property i need to build expression.
I recommend reading this: How do I change boolean properties with one click in PropertyGrid.
It extends the PropertyGrid control and defines its checkbox controls using UITypeEditor.
As Reza mentioned, your choice of control does not appear optimal. You should probably create a form with TextBox, CheckBox, ComboBox etc. Or make use of DataGridView if your display is catering for multiple records at same time.
If you most definitely want to customize PropertyGrid, here is my another answer which might help you start with.
Linked answer:
You can make use of TrackBar. Note that PropertyGrid by default does
not allow you to add controls like these to it. So, you will need to
do some work here. You will need to create a class that inherits from
System.Drawing.Design.UITypeEditor. Next you will have to set the
editor attribute for the property that has to display track bar as
control. Note that unless you do custom paint, it will be shown as
modal dialog or as dropdown editor.

propertygrid object with custom editor like a slider

In my windowsForm application I use a PropertyGrid to edit the instances of my class: some of these properties are floating point with maximum and minimum item.
I wish modify them by a slider or something like it.
I've found this: http://www.visualhint.com/propertygrid but is not free..
do you have an idea to help me?
You can make use of TrackBar. Note that PropertyGrid by default does not allow you to add controls like these to it. So, you will need to do some work here. You will need to create a class that inherits from System.Drawing.Design.UITypeEditor. Next you will have to set the editor attribute for the property that has to display track bar as control. Note that unless you do custom paint, it will be shown as modal dialog or as dropdown editor.

Completely disable CollectionEditor

I'm using a custom dynamic class object in a PropertyGrid (too much code to post here). In a nutshell, what it does is allow me to create properties at run-time from arbitrary input (in this case XML but that's beside the point). These properties may be any type, including another custom class so they can be nested indefinitely.
The issue I'm having is that the PropertyGrid sees this class as a Collection, and has the button in the Value column that allows you to open the CollectionEditor. This (among other things) has Add and Remove buttons, both of which will fundamentally break the custom class. Rather than try and make these two complicated systems work together nicely, I'd rather simply disable the CollectionEditor altogether. I have another system which allows you to see the child objects of the class (by setting the PropertyGrid.SelectedObject to the child object) and it works fine. I'd prefer the user not even having the option of seeing the CollectionEditor, as it seems to be not at all compatible with this system.
Ideally, I'd like to just put a button in the Value column that I could capture a click-event and handle myself, but that's optional. I also don't care if I disable the CollectionEditor for just the row(s) in question or for the whole PropertyGrid. I'm not using it either way, so anything which just makes it not accessible would be good.
Have you tried deriving your own CollectionEditor and in there override some methods/events to make its form not appear and just return without doing anything?
You then need to mark your collection type properties with:
[EditorAttribute(typeof(MyCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
This will automatically launch your MyCollectionEditor when clicking on the "..." button for the marked collection property in the PropertyGrid.
You may also need to inherit PropertyDescriptor and override the GetEditor method to return your own CollectionEditor.

C# Winforms visual inheritance problem with DataGridView

From here I have created a BaseForm, then set all its BaseForm.Designer.cs private members to protected. Then has had a visually inherited/derived Form.
Now I am able to re-size or modify all the controls in the derived Form in design-time except the DataGridView. I am finding the DataGridView as locked in the derived Form, even though it is not locked in the BaseForm.
What can be the reason? What should I look/check for again?
I have a base form like this:
And I have derived a form like this:
It is a known problem..
https://connect.microsoft.com/VisualStudio/feedback/details/284335/designer-prevents-access-to-protected-datagridview-control-in-inherited-form
You can create a user control class and derive from DataGridView class
[Designer(typeof(System.Windows.Forms.Design.ControlDesigner))]
public class MyDataGridViewUserControl : DataGridView { }
I guess that VS designer locks controls that came from base classes. Because you have same initialization code you would change properties of grid inside of base class, that affects all other derived forms.
If you want to change properties of your grid, I would recommend to have separate grid for child form, since it should behave differently.
It seems an issue with some .NET controls.
There's a good writing here:
DataGridView locked on a inherited UserControl

Subclass built-in WinForms control?

I've come across the feature in Visual studio to auto-generate a subclass of a custom control using Add New Inherited User Control.
But I haven't found a clear description on how to e.g create a subclass of Button for instance. Apart from the actual way to do it, I'm also interested if VS provides helpful code-generation for this?
You just create your own class that inherits the Control, that you would like to subclass. For instance:
class BetterButton : Button { ...}
That is the easy part. Now you have the option to override various methods or properties, depending on what you want to achieve with your new Control. It could be anything, really. One thing I often see used is overriding OnPaint to get the control drawn in a custom way; and still getting the behaviour of the original control.
In terms of UserControls, I often see that a "parent" UserControl contains some UI logic and basic UI elements, while the subclassed controls are refinements of the parent for specific use.

Categories

Resources