ObjectListView显示图标 [英] ObjectListView show icons

查看:296
本文介绍了ObjectListView显示图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图把在ObjectListview图标,这是我的一段代码中图标应该已经放:

Trying to put icons in ObjectListview, here's my piece of code where icon should have been put:

objectListView1.SmallImageList = imageList1;

        deleteColumn.IsEditable = true;
        deleteColumn.ImageGetter = delegate
        {
            return 0;
        };
        deleteColumn.AspectGetter = delegate
        {
            return "Delete";
        };



imageList1已有的图片,该代码应该把旁边的图标删除,但它没有出现在所有的,看遍了食谱和谷歌,我仍然不知道。 ?谁能帮我

imageList1 already have an image, this code should have put an icon next to "Delete", but it did not appear at all, looked through cookbooks and Google and I still have no idea. Can anyone help me?

这是以防完整形式的代码需要:

this is the full form code in case needed:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
    public Form1()
    {
        InitializeComponent();
        objectListView1.AllowDrop = true;
        objectListView1.DragEnter += new DragEventHandler(objectListView1_DragEnter);
        objectListView1.DragDrop += new DragEventHandler(objectListView1_DragDrop);
        objectListView1.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.SingleClick;
        objectListView1.CellEditStarting += deleteItems;
        objectListView1.SmallImageList = imageList1;

        deleteColumn.IsEditable = true;
        deleteColumn.ImageGetter = delegate
        {
            return 0;
        };
        deleteColumn.AspectGetter = delegate
        {
            return "Delete";
        };
    }

    private void objectListView1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.Copy;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }

    private void objectListView1_DragDrop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
        {
            string[] droppedFiles = (string[]) e.Data.GetData(DataFormats.FileDrop);
            foreach (string path in droppedFiles)
            {
                if (File.Exists(path))
                {
                    FileObject fo = new FileObject(path, "added later"); 
                    objectListView1.AddObject(fo);
                }
            }
        }
    }

    private void deleteItems(object sender, BrightIdeasSoftware.CellEditEventArgs e)
    {
        if(e.Column == deleteColumn)
        {
            e.Cancel = true;
            objectListView1.RemoveObject(e.RowObject);
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

}

}

推荐答案

为了对图像旁边一列中的文本出现,你必须:

In order for images to appear next to the text in a column, you must:


  1. 连接 ObjectListView 的ImageList (使用 SmallImageList 属性);

  2. 安装为列的 ImageGetter 委托,它必须显示图像;

  3. 确保有在的ImageList

  1. Connect the ObjectListView to an ImageList (using the SmallImageList property);
  2. Install an ImageGetter delegate for the column that must show the images;
  3. Make sure that there are actually images in the ImageList.

通过这个工作,图像会出现实际图像(我只是测试这一点)。

With this done, images will appear (I just tested this).

有一个陷阱,但。从你的问题,我怀疑是删除列可能无法在 ObjectListView 的第一列。以上步骤只允许你在第一个栏显示的图像。对于后续列,则必须将 ShowImagesOnSubItems 属性为True。莫非是吧?

There is one catch, though. From your question, I suspect that the "Delete" column may not be the first column in the ObjectListView. The above steps only allow you to show an image in the very first column. For subsequent columns, you will have to set the ShowImagesOnSubItems property to True. Could that be it?

这篇关于ObjectListView显示图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆