Images in ListView subitem

后端 未结 2 1069
感情败类
感情败类 2021-01-03 02:10

How to add an image instead of text for a listview subitem? Like http://i44.tinypic.com/2mzz6s6.png ?

here is normally how I add a string:

ListViewIt         


        
2条回答
  •  情深已故
    2021-01-03 02:55

    If you need the icon to be in the first column, then it could be easily done by creating an ImageList with images you want to display, assigning it to the SmallImageList property of the ListView and setting appropriate ImageIndex for the item. Like this:

    listView1.SmallImageList = YourImageList;
    ListViewItem lvi = new ListViewItem();
    lvi.SubItems.Add("A");
    lvi.SubItems.Add("B");
    lvi.SubItems.Add("C");
    lvi.ImageIndex = 2; // this will display YourImageList.Images[2] in the first column
    listView1.Items.Add(lvi);
    

提交回复
热议问题