编程方式检查的CheckBoxList的项目,其中的文字等于我想要什么 [英] Programatically Check an Item in Checkboxlist where text is equal to what i want

查看:147
本文介绍了编程方式检查的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);
    }
  }

  int index = checkedListBox1.Items.IndexOf(value);

  if (index >= 0)
  {
    checkedListBox1.SetItemChecked(index, true);
  }

这篇关于编程方式检查的CheckBoxList的项目,其中的文字等于我想要什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆