C#实现在listview中插入图片实例代码
C#实现在listview中插入图片实例代码
第一步:在窗体中拖入ListView控件和imageList控件;
第二步:设置imageList控件的Images属性,添加你想要的图片;
第三步:设置ListView控件的SmallImageList、LargeImageList、StateImageList属性为imageList;
第四步:编辑ListView控件项的ImageIndex行为你就会发现图片成功显示出来了!
附:在ListView控件中添加选项的代码
privatevoidbutton1_Click(objectsender,EventArgse)
{
if(textBox1.Text=="")
{
MessageBox.Show("添加的内容不能为空");
textBox1.Focus();//获取焦点
}
else
{
if(listView1.Items.Count>0)//判断列表框中是否有项
{
//循环比较是否有重复项,有则放弃添加
for(inti=0;i
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!