gpt4 book ai didi

C# : Looping forever foreach CheckedListBox item

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:21 26 4
gpt4 key购买 nike

foreach (CheckedListBox item in itemInfoCheckList.Items)
{
if (item.CheckState == CheckState.Checked)
SW.WriteLine(item.Text + " : YES");
else
SW.WriteLine(item.Text + " : NO");
}

上面的代码片段是它循环的地方……虽然只有 2 个项目下面是 iteminfochecklist 定义

 this.itemInfoCheckList.CheckOnClick = true;
this.itemInfoCheckList.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.itemInfoCheckList.FormattingEnabled = true;
this.itemInfoCheckList.Items.AddRange(new object[] {
"item 1 ",
"item 2"});
this.itemInfoCheckList.Location = new System.Drawing.Point(573, 350);
this.itemInfoCheckList.Name = "itemInfoCheckList";
this.itemInfoCheckList.Size = new System.Drawing.Size(197, 38);
this.itemInfoCheckList.TabIndex = 143;

最佳答案

代替这段代码

foreach (CheckedListBox item in itemInfoCheckList.Items)

使用此代码

foreach (Object item in itemInfoCheckList.CheckedItems)

关于C# : Looping forever foreach CheckedListBox item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6459737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com