Anyone who coulf help me in loading listview items to another listview? i want to load items one by one using "selected" property and all items by using "For each" statement..

and also i want to know hoe to track down duplicates with 1 column as a basis.. anyone who could help me with this??? thanks a lot..

Dani AI

Generated

Short answer first: the approach depends on which "ListView" you mean. The code in this thread (and 's examples) looks like classic/WinForms ListView (items + SubItems). If you are on ASP.NET ListView (templated control), the correct pattern is to operate on the underlying data source and rebind the target ListView.

Windows Forms (VB.NET)

  • Copy only selected items: iterate the SelectedItems collection and add a clone of each item to the destination. Cloning preserves subitems and images.
  • Copy all items and skip duplicates: keep a HashSet of the key column (trim + case-normalize) and only add when the key is new.
  • Do not modify a collection while iterating it — iterate over a snapshot (e.g., SelectedItems.Cast(Of ListViewItem)().ToArray()).

Example (WinForms):

' copy selected items
For Each src As ListViewItem In lvSource.SelectedItems
    lvDest.Items.Add(CType(src.Clone(), ListViewItem))
Next

' copy all, skipping duplicates on column 0
Dim seen As New System.Collections.Generic.HashSet(Of String)(StringComparer.InvariantCultureIgnoreCase)
For Each src As ListViewItem In lvSource.Items
    Dim key = src.SubItems(0).Text.Trim()
    If seen.Add(key) Then
        lvDest.Items.Add(CType(src.Clone(), ListViewItem))
    End If
Next

Reference: ListViewItem.Clone and HashSet(Of T) for fast duplicate checks (Clone, HashSet).

ASP.NET WebForms ListView

  • Treat the ListView as a view over data. Collect selected item keys (via checkbox/command and DataKey), then filter or build a new data collection for the target ListView and call DataBind.
  • To remove duplicates server-side, use LINQ grouping or a HashSet on your data key before binding.

Example (data-level duplicate removal):

Dim unique = data.GroupBy(Function(r) r.Key).Select(Function(g) g.First()).ToList()
MyListView.DataSource = unique
MyListView.DataBind()

Reference: ASP.NET ListView control and LINQ GroupBy (ListView, GroupBy).

Troubleshooting notes

  • Compare trimmed/lowercased keys to avoid false duplicates.
  • If icons/subitems disappear after copying, clone preserves them; ensure the destination has matching columns and an ImageList if used.
  • For large lists, HashSet checks are O(1) and preferable to nested loops.

This expands on 's loop idea with safer, modern VB.NET patterns and covers both WinForms and ASP.NET scenarios so can pick the right approach.

Recommended Answers

All 4 Replies

Anyone who coulf help me in loading listview items to another listview? i want to load items one by one using "selected" property and all items by using "For each" statement..

and also i want to know hoe to track down duplicates with 1 column as a basis.. anyone who could help me with this??? thanks a lot..

asus, style pa.. bal an mo lang dg na pro... heheh.. ^_^long time no communication ahhh...
sir.. diri man lang ta gali ma kit anay... sab ta man da b post ko.. heheh.........

sir... heheh la dyapon reply.. sorry ligad ahh.. dial up lang daan internet to kag kay boss lang tanan kay ara s kwarto yahh..

txt1.text =

for each li in listview1.listitem
if

next

txt1.text = a

for each li in listview1.listitem
if li.text = a then
msgbox "weeeee"
end if

next

sorry... disturbance is here...^_^

txt1.text = a

for each li in listview1.listitem
if li.text = a then
msgbox "weeeee"
end if
next


for each li in listview1.listitem
set list = listview2.listitem.add (, , li.text)
list.subitem(1) = li.subitem(1)
next

cge ahh.. daw into ba.. heheh.. sir txtman b la gd rep?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.