[問題] 拖曳ListView中的Item到外部程式執行

看板C_Sharp (C#)作者 (原味洋芋片)時間9年前 (2016/08/02 01:23), 9年前編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
請教各位高手 我目前想用ListView做出檔案總管的效果 ListView中的物件(item)都代表一個個的檔案 如果我想用拖曳的方法執行外部程式 (例如將一個代表txt檔的item拖曳到桌面上的記事本icon(捷徑), 就可以用記事本開啟這個檔案) 請問該怎麼做? 我可以做到把item拖曳到桌面icon上了,但放開滑鼠後沒有反應 不知哪裡有問題 以下是我寫的ListView拖曳事件處理: private void ListView1_ItemDrag(object sender, ItemDragEventArgs e) { ListViewItem item = (ListViewItem)e.Item; String fullpath = item.Text; ListView1.DoDragDrop(new DataObject(DataFormats.FileDrop, fullpath), DragDropEffects.All); } 煩請指點 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.144.231 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1470072209.A.65D.html ※ 編輯: DJRobin (60.248.153.81), 08/02/2016 10:13:24

08/02 12:57, , 1F
對FileDrop,DataObject夾帶物件是字串陣列(集合)
08/02 12:57, 1F

08/02 12:58, , 2F
也可以考慮用DataObject的SetFileDropList,更明確
08/02 12:58, 2F

08/02 14:06, , 3F
確實,改成 String[] fullpath 就行了,感謝指點
08/02 14:06, 3F
文章代碼(AID): #1NduMHPT (C_Sharp)
文章代碼(AID): #1NduMHPT (C_Sharp)