加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#实现在listview中插入图片实例代码

发布时间:2020-12-15 06:08:29 所属栏目:百科 来源:网络整理
导读:C#实现在listview中插入图片实例代码 第一步:在窗体中拖入ListView控件和imageList控件; 第二步:设置imageList控件的Images属性,添加你想要的图片; 第三步:设置ListView控件的SmallImageList、LargeImageList、StateImageList属性为imageList; 第四步

C#实现在listview中插入图片实例代码

第一步:在窗体中拖入ListView控件和imageList控件;

第二步:设置imageList控件的Images属性,添加你想要的图片;

第三步:设置ListView控件的SmallImageList、LargeImageList、StateImageList属性为imageList;

第四步:编辑ListView控件项的ImageIndex行为你就会发现图片成功显示出来了!

附:在ListView控件中添加选项的代码

  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 = "";

        }

 

      }

    }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读