How to insert a check box inside a list box in C#?(如何在 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# 中的列表框中插入复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C# 中的列表框中插入复选框?


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01