【问题标题】:c# checking for checkedListBox check state [duplicate]c#检查checkedListBox检查状态[重复]
【发布时间】:2015-02-04 01:30:33
【问题描述】:

我有一个checkedListBox,它在检查项目时将字符串放入文本框。

private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
     if (checkedListBox1.GetItemCheckState(e.Index) == CheckState.Checked)
     {
          textBox1.Text = textBox1.Text + checkedListBox1.Items[e.Index].ToString();
     }
} 

这似乎不能正常工作,当我检查一个项目时它不做任何事情,当我取消选中一个项目时,字符串被添加到文本框。

我如何检查该项目是要被选中还是未选中,如果复选框被选中,我的代码似乎正在工作。

【问题讨论】:

    标签: c# winforms checkedlistbox


    【解决方案1】:

    该项目的状态尚未“提交”。请改用e.NewValue

        private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Checked)
            {
                textBox1.Text = textBox1.Text + checkedListBox1.Items[e.Index].ToString();
            }
        } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      • 2013-07-18
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      相关资源
      最近更新 更多