WinForm Review [3] ListBox control

Source: Internet
Author: User

1. List of attribute events:

    • The selection type of the entries in the SelectionMode component, that is, multiple selection (multiple), single
    • The Rows list box shows the total number of rows
    • Selected detect if the entry is selected
    • The type returned by SelectedItem is ListItem, which gets the selected entry in the list box
    • Total number of entries in the Count list box
    • SelectedIndex the index value of the selected item in the list box
    • Items refers to all items in a list box, and the type of each item is ListItem
    • SelectedIndexChanged triggering an event when the selection changes

2. Take the selected value from the list box

Listbox.selectedvalue

3. Add the items in the list box dynamically:

LISTBOX.ITEMS.ADD ("Items to be added");

The following is still an example to review:

The code is as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.Drawing;usingSystem.IO;usingSystem.Windows.Forms;namespaceGakki album 2{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        //a generic collection that stores the full path of a filelist<string> list =Newlist<string>(); //Initialize the listbox when the form is loaded        Private voidForm1_Load (Objectsender, EventArgs e) {            stringPath = Application.startuppath +@"\gakki"; string[] Arrpics =directory.getfiles (path);  for(inti =0; i < arrpics.length; i++)            {                stringPicname =Path.getfilename (Arrpics[i]);            LISTBOX1.ITEMS.ADD (Picname); }            //load the full path into the generic collectionlist.        AddRange (Arrpics); }        Private voidListbox1_mouseclick (Objectsender, MouseEventArgs e) {pictureBox1.Image=Image.FromFile (List[listbox1.selectedindex]); }    }}

Code Link: http://pan.baidu.com/s/1gf5r3Uj Password: hxme

WinForm Review [3] ListBox control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.