如何从字符串以逗号分隔的文本框中设置checkedlistbox中的已检查项目-C# [英] How to set checked item in checkedlistbox from a TextBox with string separated by comma - c#

查看:124
本文介绍了如何从字符串以逗号分隔的文本框中设置checkedlistbox中的已检查项目-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从逗号分隔的逗号中选择项目并选中复选框列表中的内容时遇到问题

I have problem to select item from string separated comma and check item in checkedlistbox

如何从字符串分隔的逗号中选择条目,然后在checkedlistbox中选中?
预览我的程序

从此文件下载我的项目
下载
如何使用文本框和逗号分隔签入清单框

当我的清单框连接到SQl数据库时,对于文本框(用逗号分隔)没有任何作用

When My checkedlistbox is connect to SQl database is no action for TextBox Separated by comma

使用注释中的SQL脚本下载新程序

推荐答案

将此代码插入button2单击,它应该可以工作:

Insert this code in your button2 click and it should work :

string s = textBox1.Text.ToString();
        string[] values = s.Split(',');
        for (int i = 0; i < values.Length; i++)
        {
            values[i] = values[i].Trim();
        }

        for (int i = 0; i < checkedListBox1.Items.Count; i++)
        {
            checkedListBox1.SetItemChecked(i, false);//First uncheck the old value!
                                                     //
            for (int x = 0; x < values.Length; x++)
            {
                if (checkedListBox1.Items[i].ToString() == values[x].ToString())
                {
                    //Check only if they match! 
                    checkedListBox1.SetItemChecked(i, true);
                }
            }
        }

这篇关于如何从字符串以逗号分隔的文本框中设置checkedlistbox中的已检查项目-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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