How can I set an icon for a ListViewSubItem?

前端 未结 7 562
既然无缘
既然无缘 2020-12-05 19:36

In a ListView you can have icons on each item.
When viewing in Details-mode, the icon is shown in the left-most column.

Can I show an icon in some other column?<

相关标签:
7条回答
  • 2020-12-05 20:04

    ObjectListView is an open source wrapper around a .NET Winforms ListView. It supports images on subitems using the p/invoke strategy that that @ligget78 mentioned. It also solves many other common problems with a ListView.

    It allows you to make very nice looking ListViews with a minimum effort:


    (source: sourceforge.net)

    0 讨论(0)
  • 2020-12-05 20:04

    Inherit from ListView and draw your own icons.

    public class MyListView : ListView
    {
        protected override void OnDrawSubItem(System.Windows.Forms.DrawListViewSubItemEventArgs e)
        {
            base.OnDrawSubItem(e);
        }
    }
    
    0 讨论(0)
  • 2020-12-05 20:12

    Use P/Invoke and send LVM_SETITEM message to the listview (you should set LVS_EX_SUBITEMIMAGES style on control creation or via LVM_SETEXTENDEDLISTVIEWSTYLE), specify the subitem index and the corresponding image index. You will need to do it for every list item you insert.

    0 讨论(0)
  • 2020-12-05 20:14

    There's no .NET support for this.

    Have a look at this project.

    0 讨论(0)
  • 2020-12-05 20:18

    Take a loot at this:

    http://social.msdn.microsoft.com/forums/en-US/winforms/thread/d25b4ffa-2ea4-43cd-a3ae-8dd0387197ae/

    In addition to the accepted answer, you should handle the DrawItem event as well, or it will not work.

    0 讨论(0)
  • 2020-12-05 20:19

    The icon is shown in the "first" column, and this is also the basis for the keyboard prefix search. One possible solution could be to reorder the columns by setting the DisplayIndex of the first column to something else.

    listView1.Columns[0].DisplayIndex = 1;
    

    This of course only works if you need an icon in only one column.

    0 讨论(0)
提交回复
热议问题