2017-11-17 4 views
1

다른 컨트롤과 함께 여러 개의 CheckedListBox 항목이 포함 된 양식이 있습니다. 나는 각 컨트롤을 반복하고 속성 값을 설정하려고합니다. 아쉽게도 SetItemChecked 속성은 Control 클래스에서 사용할 수 없으므로 컨트롤의 상태를 조작하는 방법을 알아낼 수 없습니다.Visual C#, 어떻게 컨트롤을 사용하여 SetItemChecked 속성을 설정할 수 있습니까?

(Controls[i] as CheckedListBox).SetItemChecked(0,true); 

내가이 하나의 잘 모르겠지만, 그것은 또한 작동 할 수 있습니다 :

for (int i = 0; i < Controls.Count(); i++) { 
    switch(Controls[i].GetType().ToString()) { 
    case "System.Windows.Forms.TextBox": 
    case "System.Windows.Forms.RichTextBox": 
     Controls[i].Text=i.ToString(); 
     break; 
    case "System.Windows.Forms.CheckedListBox": 
     Controls[i].SetItemChecked(0,true); 
     // ^^ This line doesn't work, because SetItemChecked is not available 
     break; 
    default: 
     Controls[i].Tag=i; 
     break; 
    } 
} 
+0

귀하의 편집을 위해 Mr. Alford! –

답변

3

당신은 이런 CheckedListBox으로 제어 캐스트 할 수 있습니다 : 여기

내가 지금까지 가지고 무엇을 :

CheckedListBox myCbList= (ChecekdListBox) Controls[i]; 
myCbList.SetItemChecked(0,true) 
+1

첫 번째 작품은 완벽하게 작동했습니다! 대단히 감사합니다 !!! –

관련 문제