Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 849
  • Last Modified:

display queue items in listbox

Hi all,

Somewhere in our vb.net 2003 application items are added to a queue that never exeeds a certain amount of entries (max 10: last 10 processed names). I am trying to find a simple way to show these entries in a listbox, so users can view this queue (that is updated constantly)

As this queue thing (in fact 90% of Vb.net) is completely new for me, I was wondering how I could copy the queue elements directly to the listbox.items array ??

Tim
0
tdemeyer
Asked:
tdemeyer
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use the Queue.ToArray() method and the ListBox.Items.AddRange() method:

    Private myQueue As New Queue

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        myEnqueue("cat")
        System.Threading.Thread.Sleep(500)

        myEnqueue("dog")
        System.Threading.Thread.Sleep(500)

        myEnqueue("fish")
        System.Threading.Thread.Sleep(500)

        Debug.WriteLine(myDequeue)
        System.Threading.Thread.Sleep(500)

        Debug.WriteLine(myDequeue)
        System.Threading.Thread.Sleep(500)

        Debug.WriteLine(myDequeue)
        System.Threading.Thread.Sleep(500)
    End Sub

    Private Sub myEnqueue(ByVal o As Object)
        myQueue.Enqueue(o)
        UpdateListBoxQueue()
    End Sub

    Private Function myDequeue() As Object
        Dim o As Object = myQueue.Dequeue()
        UpdateListBoxQueue()
        Return o
    End Function

    Private Sub UpdateListBoxQueue()
        ListBox1.BeginUpdate()
        ListBox1.Items.Clear()
        ListBox1.Items.AddRange(myQueue.ToArray)
        ListBox1.EndUpdate()
        ListBox1.Refresh()
        Application.DoEvents()
    End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now