Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listview Clone

Status
Not open for further replies.

RobbieD

Programmer
Mar 19, 2003
12
GB
I am having problems with listviews and have started to pull my hair out. . .I have a listview which is populated by a database table, and via a context menu option i want to get the selected listview rows to populate a second listview. . .From what i have read so far using CLONE seems to be the best way however i need help in doing this or if anyone knows a better way can they please let em know. . .

Thanks in Advance
 
Hi RobbieD,
Not sure if this helps, but hopefully it's near what you're after. Two listviews (Listview1 and Listview2) and a button (Button1) should get this running on a form. Clicking the button transfers the selected items from Listview1 to Listview2. (Switch the View properties of the listviews to Detail to see it better.) Hope it helps!
Code:
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListView1.Columns.Add("column id", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("date", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("milliseconds", 100, HorizontalAlignment.Left)

        ListView2.Columns.Add("column id", 100, HorizontalAlignment.Left)
        ListView2.Columns.Add("date", 100, HorizontalAlignment.Left)
        ListView2.Columns.Add("milliseconds", 1200, HorizontalAlignment.Left)
        Dim i As Int16
        For i = 0 To 20
            Dim str(3) As String
            str(0) = "Item " & i
            str(1) = Now.Date.ToString
            str(2) = Now.Date.Millisecond.ToString
            Dim itm As New ListViewItem(str)
            ListView1.Items.Add(itm)
        Next

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim itm As ListViewItem

        For Each itm In ListView1.SelectedItems
            Dim newItm As ListViewItem = itm.Clone
            ListView2.Items.Add(newItm)
        Next
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top