How to set checked item in checkedlistbox from a T

2019-09-29 06:57发布

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

How can I select item from string separated comma and then check in checkedlistbox? Preview My Program

download My project from this file Download How can check in checkedlistbox with textbox and separated comma

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

Download New Program with SQL Script From Comment

1条回答
Evening l夕情丶
2楼-- · 2019-09-29 07:49

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);
                }
            }
        }
查看更多
登录 后发表回答