我怎样才能设置一个ListViewSubItem图标?图标、ListViewSubItem

由网友(为沵停留゛)分享简介:在一个ListView,你可以对每一个项目的图标。在详细模式观看时,该图标显示在最左边的列In a ListView you can have icons on each item.When viewing in Details-mode, the icon is shown in the left-most c...

在一个ListView,你可以对每一个项目的图标。 在详细模式观看时,该图标显示在最左边的列

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?

推荐答案

的ListView 控件不支持在分项图像本身。最容易做的事情是切换到的DataGridView 和使用 DataGridViewImageColumn 。如果这是不可能的,那么你就需要使用自定义绘制支持,在的ListView 控制自己绘制的图标。要做到这组 ListView.OwnerDraw = TRUE 并办理 ListView.DrawSubItem 的ListView。 DrawColumnHeader 事件。

The ListView control does not support images in sub-items natively. The easiest thing to do is switch to a DataGridView and use a DataGridViewImageColumn. If that is not possible, then you'll need to draw the icons yourself using the custom draw support in the ListView control. To do this set ListView.OwnerDraw = true and handle the ListView.DrawSubItem and ListView.DrawColumnHeader events.

private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
    // Only interested in 2nd column.
    if (e.Header != this.columnHeader2)
    {
        e.DrawDefault = true;
        return;
    }

    e.DrawBackground();
    var imageRect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Height, e.Bounds.Height);
    e.Graphics.DrawImage(SystemIcons.Information.ToBitmap(), imageRect);
}

private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
    e.DrawDefault = true;
}
阅读全文

相关推荐

最新文章