以编程方式检查Checkboxlist中的文本等于我想要的项目 [英] Programmatically Check an Item in Checkboxlist where text is equal to what i want
本文介绍了以编程方式检查Checkboxlist中的文本等于我想要的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中,我试图检查CheckBoxList中的文本是否等于我所需要的项目。
In C#, I am trying to Check an item in a CheckBoxList where the text equals what I require.
我将修改代码以检查存在于其中的项目
I would modify the code to check items that exist in the database.
如果您想举一个例子,我需要选择等于abc的复选框框
推荐答案
假定CheckedListBox中的项目为字符串:
Assuming that the items in your CheckedListBox are strings:
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if ((string)checkedListBox1.Items[i] == value)
{
checkedListBox1.SetItemChecked(i, true);
}
}
Or
int index = checkedListBox1.Items.IndexOf(value);
if (index >= 0)
{
checkedListBox1.SetItemChecked(index, true);
}
这篇关于以编程方式检查Checkboxlist中的文本等于我想要的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文