添加imagelist控件,把listview里面的largeimagelist属性和smallimagelist属性都设置为添加的imagelist。
可以通过this.imageList1.Images.Add(string key , Icon icon)来添加带键值的icon,这样就可以通过item.imagekey = key;使动态添加的item获取到对应key值的Icon
<strong><span style="font-size:18px;"></span></strong>
<strong><span style="font-size:18px;">这是一个listview的item双击事件的实例</span></strong>
<strong><span style="font-size:18px;">this.listView1.MouseDoubleClick += new MouseEventHandler(listView1_Item_MouseDoubleClick);</span></strong>
<pre class="csharp" name="code"><strong><span style="font-size:18px;"></span></strong>
<strong><span style="font-size:18px;">private void listView1_Item_MouseDoubleClick(object sender, MouseEventArgs e)
{
//ListViewItem item = (ListViewItem)sender;
if (listView1.SelectedItems.Count > 0)
{
if (MessageBox.Show("确定要下载此App吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
if (listView1.SelectedItems[0].Tag is App)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();//文件是openfiledialog
if (fbd.ShowDialog() == DialogResult.OK)
{
App app = listView1.SelectedItems[0].Tag as App;
int idx = app.AppAddress.LastIndexOf('\\');
if (idx >= 0)
{
string path = fbd.SelectedPath + "\\" + app.AppAddress.Substring(idx + 1);
File.MoveFile(app.AppAddress, path);
if (File.isSuccess == true)
{
MessageBox.Show("下载成功", "提示", MessageBoxButtons.OK);
AddApptoListview2(app);
}
}
}
//MessageBox.Show(listView1.SelectedItems[0].Text);
}
}
}
}</span></strong>