2012-12-24 186 views

回答

1

這是原油和簡單,但它會給你一個起點。請注意,有許多方法可以解決這個問題,並且您將需要弄清楚任何驗證方式以及您的應用程序所需的驗證方式。最大的障礙似乎是獲取對雙擊目標項目的引用(同樣重要的是,確保如果用戶雙擊ListView控件的空白區域,則最後選擇的項目不會被添加。錯誤

希望這有助於:

Public Class Form1 

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 
     Me.ListView1.FullRowSelect = True 
     Me.ListView2.FullRowSelect = True 
    End Sub 


    Private Sub AddItemToSecondList(ByVal item As ListViewItem) 
     ' NOTE: We separate this part into its own method so that 
     ' items can be added to the second list by other means 
     ' (such as an "Add to Purchase" button) 

     ' ALSO NOTE: Depending on your requirements, you may want to 
     ' add a check in your code here or elsewhere to prevent 
     ' adding an item more than once. 
     Me.ListView2.Items.Add(item.Clone()) 

    End Sub 


    Private Sub ListView1_MouseDoubleClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDoubleClick 

     ' Use the HitTest method to grab a reference to the item which was 
     ' double-clicked. Note that if the user double-clicks in an empty 
     ' area of the list, the HitTestInfo.Item will be Nothing (which is what 
     ' what we would want to happen): 
     Dim info As ListViewHitTestInfo = Me.ListView1.HitTest(e.X, e.Y) 

     'Get a reference to the item: 
     Dim item As ListViewItem = info.Item 

     ' Make sure an item was the trget of the double-click: 
     If Not item Is Nothing Then 
      Me.AddItemToSecondList(item) 
     End If 

    End Sub 


End Class 
+0

我試圖做同樣的事情,並會收到錯誤我想,也許我不理解整個則hitTest和克隆功能,你能拼寫。它出來了(我對此很新) – SonShawk

相關問題