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.
Related
Win forms problem.
I have the following structure
Form
-> User Control
-> -> Panel
-> -> -> GridViewControl
When the grid view control adds a new row, the user control does not resize. I would like the user control to resize (and the panel as well ) to accommodate the increasing sized grid control.
Is there a way to configure properties to do this? Or do I need to do something programmatic?
I am thinking I may have to learn how to use delegates and notify the parent that the child control has resized so it can respond appropriately?
Particularly I recomend you to just use scroll bars and avoid a bigger form, but whatever, you can just use the ControlAdded or the SizeChanged event of GridView or DataGridView. You really have to learn about delegates and events.
So inside the event, just check the count of itens and resize as you want.
I want to display something like the following :-
Each row is about a process (information like PID, Parent etc.). User can check the checkbox and click Launch button to get some dynamic details about that process.
The problem is that CheckedListBox control doesn't allow more than one columns and other controls like ListView (which allow multiple columns) don't allow controls like checkbox to be embedded in a columns.
I want to know if there is a control which will allow me to have a list of custom controls where each custom control contains a checkbox, Some Text and Some Dynamic Text.
How can this be achieved in Windows Forms? Thanks in advance.
You can use either of these options:
DataGridView (Example)
You can use DataGridView to show multiple columns of different types, including TextBox, Label, CheckBox, ComboBox, Image, Button, Link. You also can customize appearance of the grid by custom painting or adding new custom column types.
UserControl
You can create a composite control or UserControl containing any other controls which you need and use it as a row template, then you can show all rows by hosting multiple instance of that user control in a Panel or FlowLayoutPanel.
TableLayoutPanel (Example)
You can use a TableLayoutPanel containing multiple columns and rows. Each cell of TableLayoutPanel can host a control.
DataRepeater
You can use a DataRepeater control to create a row template and show a list of rows using that template.
Example 1 - DatGridView
If you want to use data binding and show specific controls including TextBox, Label, CheckBox, ComboBox, Image, Button, Link a row, DataGridView is great. It's customize-able and you can add some other different column types or customize painting of the grid or benefit from wide range of useful events for validating and so on.
In following image you can see a DataGridView with RowHeaderVisible and ColumnHeaderVisible set to false to act like a List of fields without header:
Example 2 - UserControl
If you need custom control to host more complicated controls or having more control on components or show them in a different layout than columns, you can create a UserControl hosting your components, then:
If you only want top-down flow, Use a Panel and add your user control to it with Dock property of control set to Top.
If you may want flows other than top-down Use a FlowLayoutPanel to add instances of your control to it.
Create a UserControl
Add instances of it to your Panel or FlowLayoutPanel
You could use the TableLayoutPanel container.
I want to know if there is a control which will allow me to have a
list of custom controls where each custom control contains a checkbox,
Some Text and Some Dynamic Text.
One option could be that you create the following as a separate user control,
...and as container control use container like FlowLayoutPanel and keep adding the user control into the FlowLayoutPanel.
Make sure that the direction of FlowLayoutPanel is set TopDown
this.FlowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
I have a TableLayoutPanel in a WinForm. The cells of the TableLayoutPanel are populated dynamically with custom UserControls. Each of this UserControls is used to display a Chart (with the DevExpress Charting Tools). The reason behind this is to arrange the charts in several rows and each row contains three columns.
Now since the charts are rather small, I want to give the user the opportunity to maximize each chart by double-clicking on the chart. Therefore I tried to use the MouseDoubleClick-Event.
I first used the Designer to assign the MouseDoubleClick-Event to the TableLayoutPanel. This works fine as long as the cells of the table are empty. As soon as there is a UserControl in it, the event is not fired/captured(?) any more.
I tried to set the event to the whole UserControl (in its Designer-View by defining its MouseDouybleClick-Event). But it is not captured again :(
What am I doing wrong?
The MouseDoubleClick event is fired for the control that is actually double-clicked.
If you tried to double-click on one of your UserControls, then it's the UserControl that will fire the event.
EDIT:
As your Chart control on your UserControl has the DockStyle property to Fill, then it's actually the Chart control that is double-clicked (as your UserControl is not visible at all).
What you could do is to forward the event to the parent control (your UserControl):
YouUserControl.cs:
private void chartControl_DoubleClick(object sender, EventArgs e)
{
this.OnDoubleClick(EventArgs.Empty);
}
Note:
Actually, it's a bit strange to create a UserControl that only contains one control with DockStyle.Fill. What didn't you use the Chart control directly on your TableLayoutPanel? If it's because you have additional method/properties in your UserContorl, you may instead want to inherit your UserControl from your Chart control (if it's not sealed).
I would like to know - which WPF control can have grid as a child as I want to insert grid to control (dynamically)
Any control that inherits from ContentControl is capable of containing any other single control, and any control that inherits from Panel can contain multiple instances of any other control.
In practice, this means that a large number of controls can potentially contain your Grid. If you only want a single Grid to appear in the control, and you do not need any other specific behaviour, I would recommend using an instance of ContentControl
I have a WinForms user control Host with a custom UI Editor.
Through that editor, a child control (Child) can be added to Host.
(The UI Editor creates Child and sets Child.Parent = Host)
Child is handled through a Holder<Child> helper class, which is set as Tag property of e.g. a ListViewItem.
The respective code - some of it, at least - gets added to the form: Holder is created, and set as Tag, which is enough to be created at runtime, too.
However, Child is not visible to the designer - it is displayed, but it can't be selected, nor does it occur in the drop down list with controls for the parent form.
I would like to:
see the Child control in the designer, so that I can modify properties
get notified if the control is removed
Is this possible?
[edit] Thanks all for your input. I've decided to skip the designer - I hoped to throw together something quickly, but apparently it requires more planning than I should allow myself to spend on it right now.
Usethis.Controls.Add(/*Instance of the child*/); on the host class. Then for the notification add event handler for the host's ControlRemoved event (this.ControlRemoved += new ControlEventHandler(Host_ControlRemoved);).
I can't say I fully understand exactly what you are trying to do.
If you are dealing with the problem of how a "child" Control of a UserControl placed on a Form at Design-Time can be made to function as a container onto which you can drag-and-drop other controls from the Toolbox : this CodeProject article by Henry Minute may be helpful : Designing Nested Controls. For example : you have a UserControl with a Panel inside it : an instance of the UserControl is placed on a Form : in the Design-time view of the Form : you want to be able to drag-drop controls onto the Panel in the UserControl and have them become child controls of the Panel : Henry's article will show you how to do that.
This from Microsoft : How to make a UserControl object acts as a control container design-time by using Visual C#
Perhaps might also be useful, although it seems like you already have this step accomplished.