好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

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

 

       }

 

 

 

     }

 

   }

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

原文链接:http://HdhCmsTestcnblogs测试数据/ngnetboy/archive/2012/03/11/2390137.html

dy("nrwz");

查看更多关于C#实现在listview中插入图片实例代码的详细内容...

  阅读:47次