문제

I'm trying to grayed out all items in the checkbox list except checked one when I check any checkbox in the list. Here is my trail, and it is going to infinite loop.

what is the issue? any idea?

private void CheckEveryOther_Click(object sender, System.EventArgs e)
{
    for (int i = 0; i < checkedListBox1.Items.Count; i++)
    {
        var state = checkedListBox1.GetItemCheckState(i);

        if (state != CheckState.Checked && state != CheckState.Indeterminate)
        {
             checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
        }
    }        
}
도움이 되었습니까?

해결책

private void CheckEveryOther_Click(object sender, System.EventArgs e)
{
    {Control}.{ControlsEvent} -= new  EventHandler(CheckEveryOther_Click);

    for (int i = 0; i < checkedListBox1.Items.Count; i++)
    {
        var state = checkedListBox1.GetItemCheckState(i);

        if (state != CheckState.Checked && state != CheckState.Indeterminate)
        {
             checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
        }
    } 

    {Control}.{ControlsEvent} += new  EventHandler(CheckEveryOther_Click);     
}

Replace {Control} with the control you are working with, and {ControlsEvent} with the control event that is being fired.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top