如何插入在C#中的列表框内部的复选框? [英] How to insert a check box inside a list box in C#?
问题描述
我想一个代码中插入升C一个列表框里面的复选框。
关于选择在列表框中的所有项目必须得到选中复选框。
I want a code to insert a checkbox inside a listbox in c sharp. on selecting the checkbox all the items in listbox must get selected.
推荐答案
您可以使用CheckListBox来显示列表与复选框每个项目旁边。
You can use a CheckListBox to display a list with a check box next to each item.
但是,为了使,在列表中选择所有单个复选框,它必须的 的外列表框(上面或下面或旁边)。那么你可以使用如下代码:
But to make a single checkbox that selects everything in a list, it must be outside the list box (above or below or beside it). Then you can use code like:
public void SelectAllCheckBox_CheckedChanged(object s, EventArgs e)
{
foreach (var item in ListBox1.Items)
{
item.Selected = SelectAllCheckBox.Checked;
}
}
有没有控件,内部有一个复选框清单:如这是你的意思:
There is no control that has a single check box inside a list: eg this is what you mean:
+----------------------------------------+
| [x] Select All |
| Item one |
| Item two |
| Item three |
| Item four |
| Item five |
+----------------------------------------+
相反,你必须使用两个控件:一个复选框和一个单独的列表框:
Instead you must use two controls: a checkbox and a separate list box:
[x] Select All
+----------------------------------------+
| Item one |
| Item two |
| Item three |
| Item four |
| Item five |
+----------------------------------------+
这篇关于如何插入在C#中的列表框内部的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!