The items set in ListBox is the ing of the itemssource set. The following statements and definitions are provided in the API:
//// Summary: // obtain the set used to generate the control content. //// Return result: // if there is a set used to generate the control content, it is the set; otherwise, it is null. The default value is an empty set. Public itemcollection items {Get ;}
If itemssource of ListBox is list <long>, items is the list <long> type. If it is observablecollection <someclasstype>, items is the set of this type.
Through items, in addition to viewing the use of the data source, what can be done? The following describes how to use items to set the default multi-choice status when initializing ListBox.
Although it is a relatively small feature, it is worth understanding. The following is an example:
(1) first create The ListBox data source, which is a collection of listboxitem types.
List <listboxitem> items = new list <listboxitem> (); For (INT I = 1; I <= 12; ++ I) {items. add (New listboxitem () {content = I}); // the actual data used will be integer I, included in the content of ListBox} monthlb. itemssource = items;
(2) define a Public Member and set the get and set accessors to get the selected listboxitem and initialize the selected items.
Public list <int> selectedmonths {get {list <int> months = new list <int> (); foreach (listboxitem item in monthlb. items) {If (item. isselected) // The listboxitem is selected {months. add (INT) item. content) ;}} return months;} set {If (value = NULL | value. count = 0) {foreach (VAR item in monthlb. items) (item as listboxitem ). isselected = true;} else {If (value = NULL) {monthlb. itemssource = NULL; return;} foreach (VAR index in value) {If (index <0) Index = 0; // set isselected = true for the listboxitem, is selected (monthlb. items [Index] As listboxitem ). isselected = true ;}}}}
(3) set the selectionmode attribute of ListBox to the check status, that is, selectionmode = "multiple ". In this way, you can check and initialize multiple ListBox selections.
There may be a better way, but I didn't find it; if anyone knows, please tell me.
~ _~