C # implements sample code sharing for inserting pictures in a ListView

Source: Internet
Author: User
This article mainly describes the C # implementation in the ListView Insert Picture Instance Code of the relevant information, the need for friends can refer to the following

C # Implementation Inserts the picture instance code in the ListView

First step: Drag the ListView control and the ImageList control into the form;

The second step: Set the images property of the ImageList control, add the picture you want;

Step three: Set the SmallImageList, LargeImageList, and StateImageList properties of the ListView control to ImageList;

Fourth step: Edit the ImageIndex behavior of the ListView control item you will find that the picture is displayed successfully!

Attached: Code to add an option to the ListView control


 private void Button1_Click (object sender, EventArgs e) {if (TextBox1.Text = = "")        {MessageBox.Show ("added content cannot be empty"); Textbox1.focus (); Get Focus} else {if (ListView1.Items.Count > 0)//Determine if there is an item in the list box {//Loop compare if there are duplicates, or discard add Add for (int i = 0; i < ListView1.Items.Count; i++) {if (String.Compare (listview1.items[i). Text.tostring (), textbox1.text) = = 0) {MessageBox.Show ("item duplicates, cannot be added!              "); TextBox1.Text = "";              Empty text box Textbox1.focus ();            Return          }} listView1.Items.Add (TextBox1.Text.ToString ());        TextBox1.Text = ""; } else {ListView1.Items.Add (textBox1.Text.ToString ());//Add the data in the text box to the list box TextBox1.Text = "        "; }       }    }
Related Article

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.