C Implementation Inserts Picture Instance Code in listview

  • 2021-12-09 09:49:23
  • OfStack

C # Realizes Inserting Picture Instance Code in listview

Step 1: Drag ListView and imageList controls into the form;

Step 2: Set the Images property of the imageList control and add the picture you want;

Step 3: Set the SmallImageList, LargeImageList, StateImageList properties of the ListView control to imageList;

Step 4: Edit the ImageIndex behavior of the ListView control item and you will find that the image is displayed successfully!

Attachment: Code for adding options to ListView controls


  private void button1_Click(object sender, EventArgs e)

    {

      if (textBox1.Text == "")

      {

        MessageBox.Show(" Added content cannot be empty ");

        textBox1.Focus(); // Get the focus 

 

      }

      else

      {

        if (listView1.Items.Count > 0) // Determine whether there are items in the list box 

        {

          // Loop to compare whether there are duplicates, and abandon adding if there are duplicates 

          for (int i = 0; i < listView1.Items.Count; i++)

          {

            if (string.Compare(listView1.Items[i].Text.ToString(), textBox1.Text) == 0)

            {

              MessageBox.Show(" Items are duplicate and cannot be added! ");

              textBox1.Text = ""; // Empty the text box 

              textBox1.Focus();

              return;

            }

          }

          listView1.Items.Add(textBox1.Text.ToString());

          textBox1.Text = "";

        }

        else

        {

          listView1.Items.Add(textBox1.Text.ToString()); // Add data from a text box to a list box 

          textBox1.Text = "";

        }

 

      }

    }

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: