I am having some problems lately with selecting ALL items(ONLY once!) from a listbox and adding them to a listview. I am using a backgroundworker to handle this task due to big content the listview will contain and to avoid GUI freezing while performing this task.
Ok, so here is the BackgroundWorker_ProgressChanged code :
For Each item In ListBox3.SelectedItems
listView1.Items.Add(ListBox3.SelectedItem, ImageList1.Images.Count - 1).SubItems.Add("Test")
ListView1.Items("Test").SubItems.Add("")
Next
For Each item As ListViewItem In ListView1.SelectedItems
Next
End Sub
The above written code displays items in listview, but ONLY if the user selects a certain item from the Listbox3 and displays infinite times the selected items from the listbox, I want it display ONLY ONCE all selected items from the Listbox, in the Listview. I want to select ALL items automatically, without user intervention, I have tried several methods which have failed. Can someone please provide a solution to this issue ? Thanks.
BackgroundWorker
is rather pointless. Anything to do with the UI is inherently foreground work so moving data from one control to another is obviously foreground work. TheProgressChanged event handler is executed on the UI thread so using a
BackgorundWorker` is completely pointless. - jmcilhinneyListView
, let alone theSelectedItems
, when the idea is to add data to theListView
, not get data from it? This is an example of what happens when you write code without knowing what that code has to do. I'm not talking about just the end result but the steps to get there. You need to work out what the code has to do first, then implement those steps in code. If you had done that then there's no way you'd be looping through theSelectedItems
of theListView
. - jmcilhinney