试图把在ObjectListview图标,这是我的代码,其中的图标应该已经放:
objectListView1.SmallImageList = imageList1;
deleteColumn.IsEditable = true;
deleteColumn.ImageGetter = delegate
{
return 0;
};
deleteColumn.AspectGetter = delegate
{
return "Delete";
};
imageList1已有的图片,这个代码应该把旁边的“删除”图标,但它并没有出现在所有的,看遍了食谱和谷歌,我仍然不知道。 谁能帮我?
这是在需要的情况下完整形式的代码:
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)
{
}
}
}