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
Related
i want to list Gridview/listbox 3 items to each row...suppose last row have one item only, then i need to display that item to second column. and suppose i have 2 items in last row, then i need to display first item to between 1 st and 2nd column and 2nditem to 2nd and 3rd column.
suppose if i have 7 items, in this scenario i want like this
suppose if i have 8 items, in this scenario i want like this
The GridView and ListBox are using different panels to order their child items.The default item panel for GridView is ItemsWrapGrid and ListBox uses VirtualizingStackPanel. A panel is an object that provides a layout behavior for child elements it contains when the Extensible Application Markup Language (XAML) layout system runs and your app UI is rendered.
If you want to order the items with different rules, you might need to custom your own panel. You can define custom panels for XAML layout by deriving a custom class from the Panel class. You provide behavior for your panel by overriding the MeasureOverride and ArrangeOverride, supplying logic that measures and arranges the child elements.
Here is a document about the detailed information about how to custom a panel: XAML custom panels overview. And you could get an example about the detailed steps here: BoxPanel, an example custom panel.
I have a WinForms application with a GroupBox in it. I have designed a user control which groups together a bunch of textboxes and other controls so that I can apply some custom logic to them. The user control looks like the following:
I want to place this user control within my GroupBox, however doing so ends up affecting the layout of the controls within my user control (see below).
As you can see, my textboxes are all spread out and resized from how I want them to be. If I place this control directly on the main form or in a Panel (not in the GroupBox) the layout is maintained, however the moment I place it in the GroupBox everything gets messed up. Is there a way to fix this problem?
The user control seems to have a different size in the two cases. Make sure it has the same size in the group box as when you place it directly on the form. If you have used a layouting control like a FlowLayoutPanel or a TableLayoutPanel, this might be of importance.
Also be aware that winforms controls inherit properties from their parent if they are not set explicitly. E.g., if you have not set the font property of the user control and its text boxes, those will be taken from the group box.
What ended up working for me was making a separate class MyGroupBox which extends GroupBox. The class is empty, but I converted the GroupBox on my form to this and placed the user control inside, which solved the problem.
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'm looking for a container that can display content, however I'd like to avoid using e.g panel, having to clear/add child. Is there a control that fits the description or would I need to create a custom container ( using e.g the mentioned panel ), exposing some "Content" property, handling the logic within there?
Every WinForms control has "children, not child" -- the Controls property is introduced on the base Control class, so every control has a collection of children.
WPF behaves more like what you're looking for; the only WPF controls that can have multiple children are those that do specific layouts, and everything else has one child (or none).
Nothing like that exists in WinForms.
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.