VB.NET Exposing child control properties - vb.net

For a custom control I'm making, the datagridview is pretty much only going to be a customized version of the original. However, so that other controls I have made can interact with it, I have made it inherit my MetroControl class.
Since I cannot add multiple "Inherits", I have placed a DataGridView and docked it inside the control. From here I can then influence and theme it. Most of the properties are handled by my theming (such as the "RowHeadersStyle" etc..
I need to push forward the "Columns" property of the DataGridView so that the user can interact with the same column setup screen that they would as if they were using the normal DataGridView. Is there any way I can simply forward this property (as it would make it much easier for both me and the user)?

Yes, you can add a property on your UserControl that just returns the Columns property on the DataGridView (Assuming that your DataGridView is stored in field named dataGridView):
public DataGridViewColumnCollection Columns {
get { return dataGridView.Columns; }
}
That's it

Related

How can I derive a control to an inherited form in VB.Net?

everybody.
I have a VB form (named "MyBaseForm"), with an ImageList control ("MyIcons").
I want to derive MyBaseForm to another form ("MyDerivedForm"), allowing it to use MyIcons ImageList defined into the base class.
Of course what I want to do is to use the images of MyIcons to define MyDerivedForm with Designer and/or into the code.
To do that, i set MyBaseForm.MyIcons.Modifiers property to Protected (I also tried with Public and Protected Friend, with the same results...)
In this way, I expect that if i modify the MyIcons image list from the Designer view of MyBaseForm, I would find the change into MyDerivedForm.
But, if i for example add a new image to MyBaseForm.MyIcons, MyDerivedForm.MyIcons keeps being still unchanged.
It looks like when i create the derived form, VisualStudio just create a copy of the ImageList control. Which is not what i want.
To have MyDerivedForm.MyIcons updated, what I have to do is to manually remove the "MyIcons" section of file MyDerivedForm.Designer.vb, so that, when I re-build, VisualStudio re-generates that section.
Is there a way to have that control REALLY derived, or, alternatively, to force the compiler to re-create MyDerivedForm.Designer.vb at any build (without having to manually manipulate the self-generated code)?
(I am using VB.Net 2005)

How do I create a "wizard" style ui using vb.net?

The idea is that I would have a set of forms, users would click through a "forward" and "back" button, and the current form would change to a different one. My issue is that I can write code that just pops up a new form, but im not sure how to do a "replacement" of my current form. How is this usually done?
What I did recently was to create a form with buttons already in place and a large panel to contain each step. The dialog would accept an initial step in the form of a IWizStep instance, and the things would roll from there.
Each step was a class exposing a UserControl responsible for the visual aspect of the step, while the logic itself was handled by the class (it was a little more complicated that that, but that was the general idea).
The IWizStep interface, implemented by the step and accepted by the dialog, was on the lines of:
Interface IWizStep
Event StateChanged As EventHandler
ReadOnly Property Control As Control
ReadOnly Property Title As String
ReadOnly Property CanMovePrevious As Boolean
ReadOnly Property CanMoveNext As Boolean
Function MovePrevious As IWizStep
Function MoveNext As IWizStep
End Interface
To put everything together, a controller class would know how to compose the steps necessary for each given action. Therefore I had a controller for, say, "Emit Order", which needed some 10 steps, and a controller for "Emit Orders in Batch", which needed only a couple of steps.
Create a set of UserControls, and add and remove them from a Panel in a single form. (and set Dock to Fill)
You could define a user control which acts as a "wizard". It just needs the buttons you have and an array of content panels, just have it switch through the panels when the buttons are pressed assuming a certain condition is met within the controls on the panel. There's no real definitive "wizard" maker, since it's pretty easy to roll your own wizard.
You don't need to do a "replacement" of your current form really, you could just add a new one to the project. If you do need to for whatever reason, just grab the control collection with Me.Controls, copy that somewhere, and put the new controls up. When you don't need the wizard, swap them out again. It's generally best practice to make a new form however!

Datagrid View in a custom control

I am trying to add datagridview control in my custom control but i failed.
I started creating new project[windows custom control library], added datagridview control on it and also added a property naming "DGVMain" which refers to datagridview control.
I compiled it.
While testing i find its properties like visible and other working but when i click on columns property it doesn't work. i.e i cannot add/edit columns into the datagridview of my custom control.
Did i miss any steps or do i need to add some more actions?
As you don't have other control within your custom control, maybe an inherited user control would be more appropriate in this case and I'm sure it will also fix your problem.

Can I change properties of inherited controls at design time?

I am using visual inheritance and was wondering if there is a way to change the properties of inherited controls at design time, preferably in the form designer. If not, then in the designer code.
I have my control declared as Public in the base class. I can access it in the child form code, but not in the form designer. Is this just not possible?
There are limitations placed within visual studio for visual inheritance. Unfortunately, derived forms\usercontrols cannot modify controls containing collections within the base, namely DataGridViewRows, ToolStrips, ListViewColumns, etc.
Microsoft Bug Report
There are ways around this in certain situations. Create a protected property in the base class that exposes the exact properties of the control you wish to modify (DataGridView.BackgroundColor, or ListView.Columns).
Your base form should be able access this property to change the components needed. I've done this for ListView.Columns, and DataGridView.rows successfully, however ToolStrip.Items would not work.
It seems to work only for certain controls, but not all and I can't understand why. On my base form I have a TabControl that within it is a ComboBox, a ToolStrip, and a DataGridView. All of them are set to Public, but I can only modify the properties of the ComboBox and not the other two controls.
I have no idea why this is.
You need to change your control visibility. Put the control property Modifiers on public and recompile the project and then you can change properties of the inherited control.

How does the tooltip control enhance all controls on the form with a new property?

When answering another question I started to wonder how I could Add new properties to all controls in a form just like the ToolTip-control does.
For example I could use that to Add a "IsDirty"-flag to all textboxes just by adding the component to the form and it would handle this for every textbox.
When adding the tooltip-control to the form all controls magically gets a new property "Tooltip on tooltip1" that can be set both programatically and in design view.
I want to be able to do my own enhancer like that.
It's an Extender Provider.