2011-09-17 2 views
3

개별적으로 선택하거나 선택을 해제 할 수있는 많은 항목이 포함 된 CheckedListBox가 있습니다.프로그래밍 방식으로 업데이트 될 때 UI 컨트롤에서 순환 이벤트 체인 방지

다음은 반대되는 여러 항목의 수퍼 집합을 나타내는 CheckBoxes입니다. 이들은 항목의 어느 부분이 반대로 선택되는지에 상응하는 3 상태입니다.

CheckedListBox 및 개별 CheckBox는 순환 참조 및 오버플로를 유발하는 변경된 유형 이벤트를 확인하기 위해 구독합니다. 프로그래밍 방식으로 변경 이벤트를 받으면 변경 이벤트를 수신하지 못하게하려면 어떻게해야합니까?

답변

2
void checkBox1_N_CheckStateChanged(object sender, EventArgs e) { 
    checkedListBox1.ItemCheck -= this.CheckedListBox1_ItemCheck; 
    // Handler body where affecting CheckedListBox1. 
    checkedListBox1.ItemCheck += this.CheckedListBox1_ItemCheck; 
} 

다른 이벤트 핸들러를 사용하지 않도록 설정하는 것이 가장 좋습니다. BoxHandler은 최소한이다

void CheckedListBox1_ItemCheck(object sender, EventArgs e) { 
    //Find which 'i' is affected. 
    arrOfCBox[i].cb.CheckStateChanged -= arrOfCBox[i].eh; 
    // Handler body where affecting checkBox[i]. 
    arrOfCBox[i].cb.CheckStateChanged += arrOfCBox[i].eh; 
} 

: (? prolly 너무 추상적) 놀라 울 정도로 답변을 수여되지 않았다 WinForms: temporarily disable an event handler

class BoxHandler 
    { 
     public EventHandler eh; 
     public CheckBox cb; 
    } 

유사하지만.

관련 문제