3 Replies Latest reply on Sep 10, 2018 1:12 PM by william.flannelly

    Reversing a List Box

    william.flannelly

      This is probably a simple solution, but is there a way to reverse the way a list box fills?

      I have a list box that fills at a very frequent rate and I would prefer to have the most recent value on top and not on the bottom of the list box.

       

      Thanks

      Bill

        • Re: Reversing a List Box
          Dan Fishman

          There are a number of ways depending how you have your listbox setup and your requirements.

           

          You could call Reverse on the collection that you are adding to the listbox. Also, if new items are added, you can use ListBox.Items.Insert.  You also could clear the list, and add items back in any order you would like.

           

          Probably for this general type of .NET forms question, PISquare is not the best place to start.  I recommend a few general web searches to start.

          • Re: Reversing a List Box
            kduffy

            Hi William,

             

            Incase you're still looking for assistance on this question, here's the exact VBA code that you could use to add an item to the beginning or the end of a Microsoft ListBox control on a Processbook display:

            Note: Value1 is a value symbol displaying cdm158

             

            Private Sub Value1_DataUpdate()
            
            Dim vDate As Variant
            Dim vStatus As Variant
            Dim vValue As Variant
            
            vValue = Value1.GetValue(vDate, vStatus)
            
            Call ListBox1.AddItem(vDate & " " & vValue)
            Call ListBox2.AddItem(vDate & " " & vValue, 0)
            
            End Sub
            

             

            And here's how it looks on the display after the value has updated a few times.

             

            Notice that Listbox1 is updating at the bottom and Listbox2 is updating at the top. This is handled by providing a value of 0 for the optional index parameter of the AddValue method.

             

            Kelsey

            3 of 3 people found this helpful