Answered by:
.Sort() as another list was sorted

Question
-
How would a list sort same as another sorted list?
ArrayofLists2(CC).Sort().Equals(ArrayofLists(CC).Sort())
I am setting a Listbox as the datasource. Would I use that somehow instead?
Error message:
Additional information: Conversion from type 'List(Of Integer)' to type 'IComparer(Of String)' is not valid.
Saturday, August 27, 2016 4:24 AM
Answers
-
I am not sure I can go with this code. I see how it works. But, I would have to have a separate db for these events as well. I am using the actual millisecond it occurs, not a timespan. Maybe I can think it through. Your code makes sense. Just not seeing the application yet.
There are entries recording in real time. But, I have to delete them and write in place of them. I have had a couple tries pretty close.I just can't get it to insert the data right.
- Marked as answer by -tE Saturday, August 27, 2016 6:02 PM
Saturday, August 27, 2016 12:34 PM
All replies
-
Asked and answered here:
https://social.msdn.microsoft.com/Forums/en-US/85ddbba2-76ef-44be-9ee8-5efef22a288f/sort-listboxes?forum=vbgeneralYou don't sort two lists the same. Put your two lists together into one list, sort that list then display it using two different properties as the display value.
Saturday, August 27, 2016 5:41 AM -
Asked and answered here:
https://social.msdn.microsoft.com/Forums/en-US/85ddbba2-76ef-44be-9ee8-5efef22a288f/sort-listboxes?forum=vbgeneralYou don't sort two lists the same. Put your two lists together into one list, sort that list then display it using two different properties as the display value.
I started a new post. I have separated the events into 3 listboxes. Works great. I don't have similar dat in each. It has to be based on the "time" based or sorted list. Like this..
Dim ListSortStart As New List(Of Integer)() Dim ListSortKeep As New List(Of Integer)() For I = 0 To ArrayofLists(CC).Count - 1 ListSortStart.Add(ArrayofLists(CC)(I)) Next ArrayofLists(CC).Sort() For I = 0 To ArrayofLists(CC).Count - 1 ListSortKeep.Add(ArrayofLists(CC)(I)) Next Dim F = ListSortKeep(L).CompareTo(ListSortStart) This would get me the index that I need to remove an replace.
- Edited by -tE Saturday, August 27, 2016 6:36 AM
Saturday, August 27, 2016 5:46 AM -
But I am sorting the time based one. How do I sort the other two the same? There is nothing to base the sort on.
Exactly. If you want the two lists to be in the same sequence, make them one list, use the time to sort that list, and then show it in as many list boxes as you want, with the time displayed in one list box, the event displayed in another, and so on.
Saturday, August 27, 2016 6:33 AM -
Exactly. If you want the two lists to be in the same sequence, make them one list, use the time to sort that list, and then show it in as many list boxes as you want, with the time displayed in one list box, the event displayed in another, and so on.
thisEvent.EventTime
I am trying to add/ remove in real time. The list I sort is right. I need it to sort the other two. So I can create this control to get the time of the event... ??? Not sure yet. How this will work. I need to think. :) As I create instances I need to remove from all 3 and rewrite them. It sort of does, b'cuz the first time based box is. I'll get it!!
Ok. So if I use the class to create the "function", I will call the same class. That I think I see. But, what's happening is it is getting the time event for each entry correct? In theory I "could" write 3 separate functions for each list eh? I haven't tried separating classes at all yet. As a matter of fact, not sure how! Can it stay on the same form I am writing or best to start a new file?- Edited by -tE Saturday, August 27, 2016 7:03 AM
Saturday, August 27, 2016 6:54 AM -
Ok. So if I use the class to create the "function", I will call the same class. That I think I see. But, what's happening is it is getting the time event for each entry correct? In theory I "could" write 3 separate functions for each list eh? I haven't tried separating classes at all yet. As a matter of fact, not sure how! Can it stay on the same form I am writing or best to start a new file?
You don't use a class to create a function and you don't 'call' a class.
You use a class so that you have something to put in a list that contains all the information you need to sort that list and to display it using whatever form of display you want. Then you create your list. Then you sort your list. Then you show it, in as many different variations as you need. Just insert the code I posted into your existing form.
Saturday, August 27, 2016 7:14 AM -
You don't use a class to create a function and you don't 'call' a class.
You use a class so that you have something to put in a list that contains all the information you need to sort that list and to display it using whatever form of display you want. Then you create your list. Then you sort your list. Then you show it, in as many different variations as you need. Just insert the code I posted into your existing form.
I understand the code block, but it isn't right for this. I wanted to display 3 separate listboxes.
1)Time
2)Event Name
3)Value which is a volume
That's all they have. So I would have to do this for each list. Which is why the code you offered is basically right. I should be able to change the Datasource to each listbox. Correct?
You have 2 variables in your sort function. This is where I am confused.
What I would do is run it 3 times. 1 for each list. If you are saying that the function does keep the time then it works as it is being entered. but it will not keep the data to sort the next pass through.
- Edited by -tE Saturday, August 27, 2016 7:59 AM
Saturday, August 27, 2016 7:54 AM -
What I would do is run it 3 times. 1 for each list. If you are saying that the function does keep the time then it works as it is being entered. but it will not keep the data to sort the next pass through.
No. You create one list, you sort that one list. Then you display it three times.
This is a complete working example. Modify the listing routine to show whatever you want in whatever listboxes you choose. They will all be in the same sort sequence. Create a form with two buttons and three listboxes. Button 1 shows the original source data. Button2 sorts it then re-displays.
Option Strict On Public Class Form1 Dim ControlEvents As New List(Of ControlEvent) Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'create some dummy data ControlEvents.Add(New ControlEvent(Now, "F1", "Fire")) ControlEvents.Add(New ControlEvent(Now.AddHours(-3), "D1", "Frontdoor")) ControlEvents.Add(New ControlEvent(Now.AddHours(-5), "D2", "SideDoor")) ControlEvents.Add(New ControlEvent(Now.AddHours(-1), "D3", "RearDoor")) ShowList(ControlEvents) End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click SortList(ControlEvents) ShowList(ControlEvents) End Sub Public Sub ShowList(_list As List(Of ControlEvent)) ListBox1.Items.Clear() ListBox2.Items.Clear() ListBox3.Items.Clear() For Each CE As ControlEvent In _list ListBox1.Items.Add(CE.ToString) ListBox2.Items.Add(CE.EventTime) ListBox3.Items.Add(CE.EventName) Next End Sub Public Sub SortList(_list As List(Of ControlEvent)) _list.Sort(Function(x As ControlEvent, y As ControlEvent) If x.EventName Is Nothing AndAlso y.EventName Is Nothing Then Return 0 ElseIf x.EventName Is Nothing Then Return -1 ElseIf y.EventName Is Nothing Then Return 1 Else Return x.EventTime.CompareTo(y.EventTime) End If End Function) End Sub End Class Public Class ControlEvent Public EventTime As DateTime Public EventControl As String Public EventName As String Public Sub New(T As DateTime, C As String, N As String) EventTime = T EventControl = C EventName = N End Sub Public Overrides Function ToString() As String Return EventTime.ToLongTimeString & " " & EventControl & " " & EventName End Function End Class
- Proposed as answer by Reed KimbleMVP Saturday, August 27, 2016 1:52 PM
Saturday, August 27, 2016 8:05 AM -
I am not sure I can go with this code. I see how it works. But, I would have to have a separate db for these events as well. I am using the actual millisecond it occurs, not a timespan. Maybe I can think it through. Your code makes sense. Just not seeing the application yet.
There are entries recording in real time. But, I have to delete them and write in place of them. I have had a couple tries pretty close.I just can't get it to insert the data right.
- Edited by -tE Saturday, August 27, 2016 10:24 AM
Saturday, August 27, 2016 9:55 AM -
I am not sure I can go with this code. I see how it works. But, I would have to have a separate db for these events as well. I am using the actual millisecond it occurs, not a timespan. Maybe I can think it through. Your code makes sense. Just not seeing the application yet.
There are entries recording in real time. But, I have to delete them and write in place of them. I have had a couple tries pretty close.I just can't get it to insert the data right.
- Marked as answer by -tE Saturday, August 27, 2016 6:02 PM
Saturday, August 27, 2016 12:34 PM -
I am not sure I can go with this code. I see how it works. But, I would have to have a separate db for these events as well. I am using the actual millisecond it occurs, not a timespan. Maybe I can think it through. Your code makes sense. Just not seeing the application yet.
There are entries recording in real time. But, I have to delete them and write in place of them. I have had a couple tries pretty close.I just can't get it to insert the data right.
Nothing in that comment makes sense. That code has no effect on your db - it is purely code to update the listboxes. It will work for any data source. It doesn't use a timespan - it uses a datetime. There is no need to 'insert' data - new data is appended to the end of the list, and the list re-sorted.
I see it now. Needed to sleep!Saturday, August 27, 2016 6:06 PM