In my vb.net (2010) wf project, I had created inside a sub (triggered by a button) a list which I'm using later (inside the same sub) as the datasource of a DataGridView in my form.
To my surprise the DataGridView can't be sorted after its creation (!) so I figured it out (and it worked) that I must sort the members of my list before I assign it as datasource to the grid.
I'm defining the list as follows:
Dim listNIK = New List(Of Class1Data)
where Class1Data is a separate class with 8 members/columns for each row: Strings, an integer and a date.
Everything worked as expected and the list was fine sorted with:
listNIK.Sort(Function(x, y) x.PARfdate.CompareTo(y.PARfdate))
where PARfdate was the date element in Class1Data
Later I decided to create a sub for deleting a selected row from the list and the datagridview but the Dim listNIK = New List(Of Class1Data) was inside the scope of my button_click sub I mentioned.
So, I took the Dim listNIK... to the beginning of my Public Class code, outside/before any sub and my new "delete selected row" sub worked like a charm!
To my surprise (again) my list/datagridview isn't sorted anymore!!
I'm not getting any errors but the intellisense list doesn't show the .sort anymore! Has only 5 choices (equals, GetType etc.). When I move the Dim listNIK inside the sub again, it gets many choices including .sort
Why is that?
And is there another way to sort my list?
To my surprise the DataGridView can't be sorted after its creation (!) so I figured it out (and it worked) that I must sort the members of my list before I assign it as datasource to the grid.
I'm defining the list as follows:
Dim listNIK = New List(Of Class1Data)
where Class1Data is a separate class with 8 members/columns for each row: Strings, an integer and a date.
Everything worked as expected and the list was fine sorted with:
listNIK.Sort(Function(x, y) x.PARfdate.CompareTo(y.PARfdate))
where PARfdate was the date element in Class1Data
Later I decided to create a sub for deleting a selected row from the list and the datagridview but the Dim listNIK = New List(Of Class1Data) was inside the scope of my button_click sub I mentioned.
So, I took the Dim listNIK... to the beginning of my Public Class code, outside/before any sub and my new "delete selected row" sub worked like a charm!
To my surprise (again) my list/datagridview isn't sorted anymore!!
I'm not getting any errors but the intellisense list doesn't show the .sort anymore! Has only 5 choices (equals, GetType etc.). When I move the Dim listNIK inside the sub again, it gets many choices including .sort
Why is that?
And is there another way to sort my list?