VB.Net 2005: listview

k3n51mm

Active member
Joined
Mar 7, 2007
Messages
40
Programming Experience
3-5
I am iterating through an arraylist to populate two columns of a listview control. Code:

VB.NET:
Expand Collapse Copy
For i As Integer = 0 To arr.Count - 1
    Dim item As String = arr(i)
    'split into required values
    Dim arrItem() = Split(item, "___")
    Dim szNum As String = arrItem(0)
    Dim szName As String = arrItem(1)
    Dim lvItem As New ListViewItem(szNum, 0)
    lvItem.SubItems.Add(szName)
    listview1.Items.Add(lvItem)
Next
As this listview is populated (it takes maybe 3-4 seconds), even though it runs on a background worker thread, it makes the form blink very fast while it fills the listview display and it looks bad.

I used the following directive on form_load:
VB.NET:
Expand Collapse Copy
Control.CheckForIllegalCrossThreadCalls = False
because this listview is created on the main program thread. Moving the fill function to another thread allows the form to be rendered, but now instead of just hanging for 4 seconds while this listview is populated, it blinks. I also moved the Split() call out of the loop, and it still blinks.

I'm happy to do this in a more elegant way, but I'll need code samples rather than URLs if possible.
 
Back
Top