0

私は2つListViewのセットアップを持っています。 ユーザーがいずれかのデータをダブルクリックしたときListview1にデータを渡す必要があります。listview2これをアーカイブするにはどうすればよいですか? vb2008を使用しています。

ここに画像があります: 画像

4

1 に答える 1

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
于 2012-12-25T15:43:52.687 に答える