Results 1 to 8 of 8

Thread: populate ListView using a thread

Threaded View

  1. #1

    Thread Starter
    New Member remusrigo's Avatar
    Join Date
    Aug 2011
    Location
    Romania, Timisoara
    Posts
    2

    populate ListView using a thread

    Hi all

    I have a procedure that populates a ListView, but it does a lot of work and it takes too much time to display all it's items (about 100-200 items). I want to use a thread to display the items as it's extracting data (real-time).

    I posted a question earlier here, but using a ListView it's not working for me...

    Code:
    Imports System.Threading
    Imports System.ComponentModel
    
    Public Class Form1
       Dim li As ListViewItem = lv.Items.Add("")
    
       Dim myThread As System.Threading.Thread = New Thread(AddressOf Me.AddItems)
    
       Public Delegate Sub ItemAdder(ByVal Input As String)
       Dim objItemAdder As ItemAdder
    
       Public Sub AddItemsDelgate(ByVal ItemToAdd As String)
          li = lv.Items.Add("")
          li.Text = ItemToAdd
       End Sub
    
       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          objItemAdder = New ItemAdder(AddressOf AddItemsDelgate)
          myThread.Start()
       End Sub
    
       Public Sub AddItems()
          Dim i As Int32
          Dim n As Double = 1
          Dim s As String = ""
    
          For i = 0 To 100
             s = n.ToString
             Me.Invoke(objItemAdder, New Object() {s})
             n *= 2
             Thread.Sleep(100)
          Next
    
       End Sub
    
    End Class
    Last edited by remusrigo; Jan 22nd, 2012 at 11:15 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width