Dear hackers, how to get access to the listBox elements, tobish my checkbox and button in it. Why I can't get the methods and properties of the Button and CheckBox classes if I request them through Items. enter image description here

help pliz

  • If you are writing to WPF, you should not want that at all. Why do you need internal elements? - VladD
  • @VladD The animation in WPF is well done, more beautiful. The meaning of the program is that people, in this case cadets, be selected and sent to print. I need to get to the IsChecked property, but in the items it is not provided - Zhenya Rubezhansky
  • And why do not you take the value of the binding? I hope you do not create the list items manually? - VladD

2 answers 2

ListBox.Items returns a collection of elements of type object. To access the properties of certain objects you need to bring the collection item to the desired type.

object item = listBox.Items[i]; if(item is CheckBox) CheckBox cbx = item as CheckBox; 
  • Even this code refuses to work ... - Zhenya Rubezhansky
  private List<CheckBox> checkingList() { List<CheckBox> checkingList = new List<CheckBox>(); for (int i = 0; i < listBoxKursants.Items.Count; i++) { if (listBoxKursants.Items[i] is CheckBox) { CheckBox c = (CheckBox)listBoxKursants.Items[i]; checkingList.Add(c); } } return checkingList; } 

I decided. In this way, we access the CheckBox as an array and access each check in the list.