Home >Backend Development >C#.Net Tutorial >C# implementation of sample code sharing for inserting pictures into listview

C# implementation of sample code sharing for inserting pictures into listview

黄舟
黄舟Original
2017-03-16 11:10:472250browse

This article mainly introduces the relevant information of C# to implement the example code of inserting pictures in listview. Friends who need it can refer to it

C# Implementation of inserting image example code into listview

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

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

Step 3: Set the SmallImageList of the ListView control. The properties of LargeImageList and StateImageList are imageList;

Step 4: Edit the ImageIndex of the ListView control itemBehaviorYou will find that the image is displayed successfully!

Attach: Code for adding options in the ListView control


  private void button1_Click(object sender, EventArgs e)

    {

      if (textBox1.Text == "")

      {

        MessageBox.Show("添加的内容不能为空");

        textBox1.Focus(); //获取焦点

 

      }

      else

      {

        if (listView1.Items.Count > 0) //判断列表框中是否有项

        {

          //循环比较是否有重复项,有则放弃添加

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

          {

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

            {

              MessageBox.Show("项目重复,不能添加!");

              textBox1.Text = ""; //清空文本框

              textBox1.Focus();

              return;

            }

          }

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

          textBox1.Text = "";

        }

        else

        {

          listView1.Items.Add(textBox1.Text.ToString()); //将文本框中的数据添加到列表框

          textBox1.Text = "";

        }

 

      }

    }

The above is the detailed content of C# implementation of sample code sharing for inserting pictures into listview. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn