[英]How do I select the top 30 items in a C# checkbox control with a single button click
I have windows app that I am building and want to be able to click one button and select the top 30 entries in a check box control. 我有正在构建的Windows应用程序,希望能够单击一个按钮并在复选框控件中选择前30个条目。 The select all is easy. 全选很容易。 Of course I could be overlooking the simplicity here, but it is not making sense right now. 当然,我可能会忽略这里的简单性,但是现在没有任何意义。
Edited; 编辑; Here is what I have that works for selecting all entries. 这是我可以选择所有条目的内容。
private void ckTop_CheckedChanged(object sender, EventArgs e)
{
// either check all or uncheck all
if (ckTop.Text == "Check all")
{
for (int i = 0; i < CLB.Items.Count; i++) CLB.SetItemChecked(i, true);
ckTop.Text = "Uncheck all";
}
else
{
for (int i = 0; i < CLB.Items.Count; i++) CLB.SetItemChecked(i, false);
ckTop.Text = "Check all";
}
}
I have tried setting the CLB.SetItemChecked(i, true); 我试过设置CLB.SetItemChecked(i,true); to a value of 4 to see if it would select the fourth entry, but that did not work. 的值设为4,以查看是否会选择第四个条目,但这不起作用。
this should do the trick for you, 这应该为您解决问题,
for (var i = 0; i < 30; i++)
{
checkedListBox1.SetItemChecked(i, true);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.