-
Sep 30th, 2014, 09:57 AM
#1
Thread Starter
Junior Member
Reverse the items in list box
Hi,
I am doing a project for production test unit. i need to reverse the order of items in the list box that is updating for each second ( to be simple the data must look like last in first out). here is the code that i am using for updating the items in the list box
Code:
lstData2.Items.Add(value & vbTab & txtStatus.Text & vbTab & Now)
Me.lstData2.Text = Me.txtTemp.Text & vbNewLine & Me.lstData2.Text
My.Computer.FileSystem.WriteAllText("C:\temp\test.txt", value & vbTab & Now & vbCrLf, True)
If lstData2.Items.Count > 20 Then
Timer.Enabled = False
txtStatus.Text = "Dangerous Reading"
txtStatus.BackColor = Color.Red
lstData1.Text = "Limit Exceeded"
MsgBox("You can't add more Items")
End If
Can any one help me please
-
Sep 30th, 2014, 10:02 AM
#2
Thread Starter
Junior Member
Re: Reverse the items in list box
I got it here is the answer, I found the code after posting this forum
Code:
Dim arr(lstData2.Items.Count - 1) As Object
lstData2.Items.CopyTo(arr, 0)
Array.Reverse(arr)
lstData2.Items.Clear()
lstData2.Items.AddRange(arr)
-
Sep 30th, 2014, 10:07 AM
#3
Thread Starter
Junior Member
Re: Reverse the items in list box
but I need to do same thing for two list boxes which I am not able to do form the above code. can any one help me please
-
Oct 1st, 2014, 01:51 AM
#4
Re: Reverse the items in list box
Originally Posted by sonu1992
but I need to do same thing for two list boxes which I am not able to do form the above code. can any one help me please
Why exactly can't that code be used on these other ListBoxes? Are we to guess? That code is going to work on any unbound ListBox so the only reason I can think of that it wouldn't work is that the ListBox is bound. You haven't mentioned that, nor have you mentioned the error that would have occurred using that code that would have confirmed that they were bound. If that code doesn't work then something that you don't expect happens instead. What? Are the ListBoxes bound? If so then you have to reverse the contents of the data source but how to do that depends on what it is.
-
Oct 1st, 2014, 02:05 AM
#5
Thread Starter
Junior Member
Re: Reverse the items in list box
Originally Posted by jmcilhinney
Why exactly can't that code be used on these other ListBoxes? Are we to guess? That code is going to work on any unbound ListBox so the only reason I can think of that it wouldn't work is that the ListBox is bound. You haven't mentioned that, nor have you mentioned the error that would have occurred using that code that would have confirmed that they were bound. If that code doesn't work then something that you don't expect happens instead. What? Are the ListBoxes bound? If so then you have to reverse the contents of the data source but how to do that depends on what it is.
Sorry I am not getting what are you asking me actually, I am very new to VB.Net that's why I am not able to post clearly about the problem that I am facing. But actually right now that code works. I am facing another problem now, I am not able to write the data from the text file to list box exactly in the same order they stored in the text file. I am getting the data into list box but not in an particular format like 0,1,2,3,.. it is displaying like 4,9,8,0,2,3,... can you help me on this issue please
-
Oct 1st, 2014, 02:19 AM
#6
Re: Reverse the items in list box
Originally Posted by sonu1992
Sorry I am not getting what are you asking me actually, I am very new to VB.Net that's why I am not able to post clearly about the problem that I am facing. But actually right now that code works.
Would you go to the doctor and expect a diagnosis without describing your symptoms? You don't need any programming experience to understand that if you want help with a problem then you explain what the problem is.
Originally Posted by sonu1992
I am facing another problem now, I am not able to write the data from the text file to list box exactly in the same order they stored in the text file. I am getting the data into list box but not in an particular format like 0,1,2,3,.. it is displaying like 4,9,8,0,2,3,... can you help me on this issue please
That's nothing to do with the topic of this thread so it belongs in a new thread of its own. One thread per topic and one topic per thread please.
-
Oct 1st, 2014, 02:26 AM
#7
Thread Starter
Junior Member
Re: Reverse the items in list box
ok thank you so much for your response. so I have to post a new thread for this topic.
-
Oct 1st, 2014, 02:30 AM
#8
Re: Reverse the items in list box
Originally Posted by sonu1992
so I have to post a new thread for this topic.
Correct.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|