问题描述
我想显示如下内容:-
每一行都与一个进程有关(PID、父级等信息).用户可以选中 checkbox
并单击 Launch 按钮以获取有关该过程的一些动态详细信息.
问题是 CheckedListBox
控件不允许超过一列,而 ListView
等其他控件(允许多列)不允许像 checkbox
嵌入到列中.
我想知道是否有一个控件可以让我拥有一个自定义控件列表,其中每个自定义控件包含一个 checkbox
、Some Text
和 一些动态文本
.
如何在 Windows 窗体中实现这一点?提前致谢.
您可以使用以下任一选项:
DataGridView(
示例2-用户控件
如果您需要自定义控件来托管更复杂的控件或对组件具有更多控制权或以与列不同的布局显示它们,您可以创建一个
UserControl
来托管您的组件,然后:- 如果您只想要自上而下的流程,请使用
Panel
并将您的用户控件添加到其中,并将控件的Dock
属性设置为Top
. - 如果您可能需要自上而下以外的流程,请使用
FlowLayoutPanel
向其中添加控件实例.
创建一个
用户控件
将它的实例添加到您的
Panel
或FlowLayoutPanel
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 likeListView
(which allow multiple columns) don't allow controls likecheckbox
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
andSome Dynamic Text
.How can this be achieved in Windows Forms? Thanks in advance.
解决方案You can use either of these options:
DataGridView (Example)
You can useDataGridView
to show multiple columns of different types, includingTextBox
,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 orUserControl
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 aPanel
orFlowLayoutPanel
.TableLayoutPanel (Example)
You can use aTableLayoutPanel
containing multiple columns and rows. Each cell ofTableLayoutPanel
can host a control.DataRepeater
You can use aDataRepeater
control to create a row template and show a list of rows using that template.
Example1-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
withRowHeaderVisible
andColumnHeaderVisible
set tofalse
to act like a List of fields without header:Example2-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 withDock
property of control set toTop
. - 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
orFlowLayoutPanel
这篇关于在 Windows 窗体中显示控件集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
- 如果您只想要自上而下的流程,请使用