日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
簡單講述VB.NET表間拖放

經(jīng)過長時間學(xué)習(xí)VB.NET表間拖放,于是和大家分享一下,看完本文你肯定有不少收獲,希望本文能教會你更多東西。

網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、成都微信小程序、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了西夏免費建站歡迎大家使用!

VB.NET表間拖放

VB.NET表間拖放有一個情況是從一個列表移動項目到另一個列表。這種情況下拖放將變得更加簡單。向窗體中添加兩個ListView控件,并把他們的AllowDrop、Multiselect、View屬性分別設(shè)置成True、True、List。并添加如下代碼:

 
 
 
  1. Private Sub ListView_ItemDrag(ByVal sender As Object, ByVal e As _
  2. System.Windows.Forms.ItemDragEventArgs) Handles ListView1.ItemDrag, _
  3. ListView2.ItemDrag
  4. Dim myItem As ListViewItem
  5. Dim myItems(sender.SelectedItems.Count - 1) As ListViewItem
  6. Dim i As Integer = 0
  7. ' Loop though the SelectedItems collection for the source.
  8. For Each myItem In sender.SelectedItems
  9. ' Add the ListViewItem to the array of ListViewItems.
  10. myItems(i) = myItem
  11. ii = i + 1
  12. Next
  13. ' Create a DataObject containg the array of ListViewItems.
  14. sender.DoDragDrop(New _
  15. DataObject(System.Windows.Forms.ListViewItem(), myItems), _
  16. DragDropEffects.Move)
  17. End Sub
  18. Private Sub ListView_DragEnter(ByVal sender As Object, ByVal e As _
  19. System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter, _
  20. ListView2.DragEnter
  21. ' Check for the custom DataFormat ListViewItem array.
  22. If e.Data.GetDataPresent(System.Windows.Forms.ListViewItem()) Then
  23. e.Effect = DragDropEffects.Move
  24. Else
  25. e.Effect = DragDropEffects.None
  26. End If
  27. End Sub
  28. Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As _
  29. System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop, _
  30. ListView2.DragDrop
  31. Dim myItem As ListViewItem
  32. Dim myItems() As ListViewItem = _ e.Data.GetData(System.Windows.Forms.ListViewItem())
  33. Dim i As Integer = 0
  34. For Each myItem In myItems
  35. ' Add the item to the target list.
  36. sender.Items.Add(myItems(i).Text)
  37. ' Remove the item from the source list.
  38. If sender Is ListView1 Then
  39. ListView2.Items.Remove(ListView2.SelectedItems.Item(0))
  40. Else
  41. ListView1.Items.Remove(ListView1.SelectedItems.Item(0))
  42. End If
  43. ii = i + 1
  44. Next
  45. End Sub

你可能不明白為什么這個例子中用的是ListView控件而不是ListBox控件,這個問題題的好,因為ListBox控件不支持多項拖放。ListView和TreeView控件有個ItemDrag事件。上面的例子中,一個ItemDrag事件句柄覆蓋了兩個控件,并在列在Handles從句。Sender參數(shù)表明哪個控件正在初始化Drag。因為DataFormats類沒有ListViewItem類型成員,數(shù)據(jù)必須傳遞給一個系統(tǒng)類型。ItemDrag創(chuàng)建了一個ListViewItem類型的數(shù)組,并用一個循環(huán)來遍歷SelectedItem集合。在DoDragDrop方法中,創(chuàng)建了一個新的DataObject并用數(shù)組來來對它進行操作??梢杂眠@種方法來拖放任何系統(tǒng)類型。

VB.NET表間拖放結(jié)論:

正像你從這些例子中所看到的一樣,為應(yīng)用程序添加拖放操作并不是很難。當(dāng)你理解了這些基本的技巧后,你就可以為你自己的程序添加拖放的代碼了 。


本文標(biāo)題:簡單講述VB.NET表間拖放
文章網(wǎng)址:http://m.5511xx.com/article/cosiocg.html