1. attribute list:
Select Type of entries in the selectionmode component, that is, multiple and single)
Total number of rows displayed in the rows list box
Selected
The returned type of selecteditem is listitem.
Total number of entries in the count list box
Index value of the selected item in the selectedindex list box
Items refers to all items in the list box. each item is of the listitem type.
2. Select the selected value from the list box.
ListBox. selectedvalue
3. dynamically add items in the list box:
ListBox. Items. Add ("items to be added ");
4. Remove a specified item:
// First, infer whether the items in the list box are greater than 0.
If (ListBox. Items. Count> 0)
{
// Remove the selected item
ListBox. Items. Remove (ListBox. selecteditem );
}
5. Clear all items:
// First, infer whether the items in the list box are greater than 0.
If (ListBox. Items. Count> 0)
{
// Clear all items
ListBox. Items. Clear ();
}
6. You can select multiple items in the list box at a time:
You only need to set the attribute selectionmode = "multiple" of the list box, and press Ctrl to select multiple
7. Two lists are linked, that is, two levels of linked menus.
// Deduce the selected value in the first list box
Switch (listbox1.selectvalue)
{
// If it is "A", add these to the second list box:
Case ""
Listbox2.items. Clear ();
Listbox2.items. Add ("A1 ");
Listbox2.items. Add ("A2 ");
Listbox2.items. Add ("A3 ");
// If it is "B", add the following to the second list box:
Case "B"
Listbox2.items. Clear ();
Listbox2.items. Add ("B1 ");
Listbox2.items. Add ("B2 ");
Listbox2.items. Add ("B3 ");
}
8. Shift the items in the list box
That is, shift up and down
The detailed idea is: Create a ListBox object and put the items to be moved in this object for the moment.
If it is an upward shift, it is to assign the value of the previous item of the selected item to the selected item, and then
Attaches the value of the newly added object to the first item of the selected item.
Detailed code:
// Define a variable for shift
Index =-1;
// Save the text and values of the current entry to a temporary variable.
Listitem lT = new listitem (ListBox. selecteditem. Text, ListBox. selectedvalue );
// The value of the selected item is equal to the value of the previous or next item.
ListBox. items [ListBox. selectedindex]. Text = ListBox. items [ListBox. selectedindex + Index]. text;
// The value of the selected item is equal to the value of the previous or next item.
ListBox. items [ListBox. selectedindex]. value = ListBox. items [ListBox. selectedindex + Index]. value;
// Replace the previous or next value of the selected item with a temporary variable
ListBox. items [ListBox. selectedindex]. test = lt. test;
// Replace the previous or next value of the selected item with a temporary variable
ListBox. items [ListBox. selectedindex]. value = lt. value;
// Place the mouse pointer on the moving item
ListBox. items [ListBox. selectedindex]. value = lt. value;
9. Move the pointer to the specified position:
(1) Move to the first entry
// Set the index of the selected item to 0.
ListBox. selectindex = 0;
(2) Move to the end
// Set the index of the selected item to ListBox. Items. Count-1.
ListBox. selectindex = ListBox. Items. Count-1;
(3). Previous
// Subtract 1 from the selected index
ListBox. selectindex = ListBox. selectindex-1;
(4). Next
// Add 1 with the selected index
ListBox. selectindex = ListBox. selectindex + 1;
This. listbox1.items. insertat (3, new listitem ("inserted after row 3rd ",""));
This. listbox1.items. insertat (index, listitem)
Listbox1.items. insert (0, new listitem ("text", "value "));