C#中listview的image添加问题和item双击事件

添加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>

 


 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值