Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取复选框列表文本_C# - Fatal编程技术网

C# 获取复选框列表文本

C# 获取复选框列表文本,c#,C#,嗨,我想将复选列表框valuetext保存在变量中。我该怎么做 private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { int a = checkedListBox1.; checkedListBox1.Hide(); label1.Text = a.ToString() ; } 让我们试试下面的代码 List<s

嗨,我想将复选列表框valuetext保存在变量中。我该怎么做

     private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        int a = checkedListBox1.;
        checkedListBox1.Hide();
        label1.Text = a.ToString() ;

    }
让我们试试下面的代码

List<string> checkedItems = new List<string>();
        foreach (var item in checkedListBox1.CheckedItems)
            checkedItems.Add(item.ToString());

        if (e.NewValue == CheckState.Checked)
            checkedItems.Add(checkedListBox1.Items[e.Index].ToString());
        else
            checkedItems.Remove(checkedListBox1.Items[e.Index].ToString());

         StringBuilder builder = new StringBuilder();
        foreach (string item in checkedItems)
        {
             builder.Append(item).Append("|");
        }
       label1.Text = builder.ToString();

发布代码,而不是截图。