다른 컨트롤과 함께 여러 개의 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;
}
}
귀하의 편집을 위해 Mr. Alford! –