ListView SortKey

D

Dave

VB6 has a SorkKey property that you can setup on the ListView control to
tell the ListView what column to use for sorting. In .NET there is a Sort()
method and a SortOrder property that you can use to manipulate the Sorting
property. My question is how do I perform the same functionality as I do
in VB6 setting the SortKey and SortOrder with the ListView.

Dave
 
A

AMDRIT

Use the ListViewItemSorter

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindowsformslistviewclasslistviewitemsortertopic.htm



Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer
object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the
ListViewItemComparer implementation.
listView1.Sort()
End Sub

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text,
CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class
 
D

Dave

This implements manual sorting. Is there such thing as automatic where you
just specify the column and the sort order ?


AMDRIT said:
Use the ListViewItemSorter

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindows
formslistviewclasslistviewitemsortertopic.htm



Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer
object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the
ListViewItemComparer implementation.
listView1.Sort()
End Sub

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text,
CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class



Dave said:
VB6 has a SorkKey property that you can setup on the ListView control to
tell the ListView what column to use for sorting. In .NET there is a
Sort()
method and a SortOrder property that you can use to manipulate the Sorting
property. My question is how do I perform the same functionality as I do
in VB6 setting the SortKey and SortOrder with the ListView.

Dave
 
A

AMDRIT

It doesn't appear so. Perhaps, you can create your own control that derives
from the listview that will implement this technology and then it will be
"automatic"

public class MyListViewItem
inherits ListViewItem
public property CompareType as Type
end Property
end Class

Public class MyListView
inherits ListView

event OnColumnClicked(object, MyColumnClickEventArgs)

Public Shadows Property Item(index as integer) as MyListViewItem
End Property

private sub ColumnClicked(object, ColumnClickEventArgs)
dim MyColumnClickEventArgs as ColumnClickEventArgs
raiseevent oncolumnclicked(me, temparg)
if not temparg.handled then
'perform customsort
end if
end sub

end Class

Dave said:
This implements manual sorting. Is there such thing as automatic where
you
just specify the column and the sort order ?


AMDRIT said:
Use the ListViewItemSorter

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindows
formslistviewclasslistviewitemsortertopic.htm



Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer
object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the
ListViewItemComparer implementation.
listView1.Sort()
End Sub

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text,
CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class



Dave said:
VB6 has a SorkKey property that you can setup on the ListView control
to
tell the ListView what column to use for sorting. In .NET there is a
Sort()
method and a SortOrder property that you can use to manipulate the Sorting
property. My question is how do I perform the same functionality as I do
in VB6 setting the SortKey and SortOrder with the ListView.

Dave
 
D

Dave

VB6 to VB.NET - not impossible, but nearly :(

should prolly throw it all away start over and do it in C#

don't want to be the one to tell management that their millions of dollars
in software investment is a throw away though


AMDRIT said:
It doesn't appear so. Perhaps, you can create your own control that derives
from the listview that will implement this technology and then it will be
"automatic"

public class MyListViewItem
inherits ListViewItem
public property CompareType as Type
end Property
end Class

Public class MyListView
inherits ListView

event OnColumnClicked(object, MyColumnClickEventArgs)

Public Shadows Property Item(index as integer) as MyListViewItem
End Property

private sub ColumnClicked(object, ColumnClickEventArgs)
dim MyColumnClickEventArgs as ColumnClickEventArgs
raiseevent oncolumnclicked(me, temparg)
if not temparg.handled then
'perform customsort
end if
end sub

end Class

Dave said:
This implements manual sorting. Is there such thing as automatic where
you
just specify the column and the sort order ?


AMDRIT said:
Use the ListViewItemSorter
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindows
formslistviewclasslistviewitemsortertopic.htm
Private Sub ColumnClick(ByVal o As Object, ByVal e As ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer
object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the
ListViewItemComparer implementation.
listView1.Sort()
End Sub

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x, ListViewItem).SubItems(col).Text,
CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class




VB6 has a SorkKey property that you can setup on the ListView control
to
tell the ListView what column to use for sorting. In .NET there is a
Sort()
method and a SortOrder property that you can use to manipulate the Sorting
property. My question is how do I perform the same functionality as
I
do
in VB6 setting the SortKey and SortOrder with the ListView.

Dave
 
A

AMDRIT

I feel your pain.

however,

You can continue to use the common controls in .Net and it will work just
fine. You can use the new common controls and implement your desired
enhancements as you wish. You can continue to use the VB 6 interface and
start reworking the backend in .Net.

There are trade off's when dealing with the next generation of VB, and that
should have been considered by the business or other decision makers prior
to deciding to move to .Net. Simply throwing it all away just to spit VB
and moving to C# doesn't change the fact that there is now a different way
to do the same things. Albeit, in some cases, it seems more cumbersome.
You do gain the fact that now, VB sits squarely in the same arena that C++
does. Granted the two may have different applications, they are now more
closely considered equals than ever before.

Have you seen what Microsoft has done to VB in .Net 2005? The certainly
demonstrated that VB was very much a viable solution in the software
development arena. Moving to VB.Net is more than an enhancement in feature
set, it is an opening to options that we didn't have (yes, even with all the
api at our disposal.)

Anyone assuming that a direct port from VB 6, to VB.Net of any production
application is sorely misguided. This is old news, we have known that there
were significant changes as early as 2001, back when we had 6 years until VB
of the old died.

The brightest side of this is that you have the lessons learned of a legacy
system. You have a code base to defer to. You do not have to rely so much
on "Subject Matter Experts" or "Business Users". All of your critical
decision trees are completed.

You still have a year before VB of the old goes under. It seems to me that
your legacy system is working in production and, barring the advent of the
latest computer plague, will continue to function when left unmarred for
some time yet. You are not completely pinned to a wall, even this late in
the game.

You may find yourself creating a more disparate system until the conversion
process is complete. Don't be afraid of that change, embrace the fact that
you are no longer solely supporting an existing system and that you now have
the ability "If I had it to do all it all over again". Knowing that you
might have to come out of your comfort zone, should be exhilarating to you
as a developer.

VB hasn't let us down, it merely graduated from high school.

I apologize for the diatribe, I just get frustrated with all the doomsday
talk when, yet another VB programmer first treads into the vast
possibilities of the next generation. Sheesh, on release day of 2005,
people were already bashing Microsoft ("The necessary evil, that it is") for
one reason or another. One size does not fit all, make of it as you will or
make your own.


Dave said:
VB6 to VB.NET - not impossible, but nearly :(

should prolly throw it all away start over and do it in C#

don't want to be the one to tell management that their millions of dollars
in software investment is a throw away though


AMDRIT said:
It doesn't appear so. Perhaps, you can create your own control that derives
from the listview that will implement this technology and then it will be
"automatic"

public class MyListViewItem
inherits ListViewItem
public property CompareType as Type
end Property
end Class

Public class MyListView
inherits ListView

event OnColumnClicked(object, MyColumnClickEventArgs)

Public Shadows Property Item(index as integer) as MyListViewItem
End Property

private sub ColumnClicked(object, ColumnClickEventArgs)
dim MyColumnClickEventArgs as ColumnClickEventArgs
raiseevent oncolumnclicked(me, temparg)
if not temparg.handled then
'perform customsort
end if
end sub

end Class

Dave said:
This implements manual sorting. Is there such thing as automatic where
you
just specify the column and the sort order ?



Use the ListViewItemSorter


ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindows
formslistviewclasslistviewitemsortertopic.htm



Private Sub ColumnClick(ByVal o As Object, ByVal e As
ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer
object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the
ListViewItemComparer implementation.
listView1.Sort()
End Sub

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x,
ListViewItem).SubItems(col).Text,
CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class




VB6 has a SorkKey property that you can setup on the ListView
control
to
tell the ListView what column to use for sorting. In .NET there is
a
Sort()
method and a SortOrder property that you can use to manipulate the
Sorting
property. My question is how do I perform the same functionality
as I
do
in VB6 setting the SortKey and SortOrder with the ListView.

Dave
 
D

Dave

I'm at least working with a couple of applications that were pretty well
structured before they were upgraded, so I got a decent upgrade. It's just
some of the features that have been discarded frustrate many of the issues.
So I vented a bit. Thanks for the diatribe and the time spent writing it.
I'm not completely frustrated because of my years of experience writing
windows software dating back to the original windows 3.0, I've been able to
solve most of my problems myself. I just get surprised sometimes when it
requires more implementation to solve a problem that VB6 solved in a line or
two of property settings.


AMDRIT said:
I feel your pain.

however,

You can continue to use the common controls in .Net and it will work just
fine. You can use the new common controls and implement your desired
enhancements as you wish. You can continue to use the VB 6 interface and
start reworking the backend in .Net.

There are trade off's when dealing with the next generation of VB, and that
should have been considered by the business or other decision makers prior
to deciding to move to .Net. Simply throwing it all away just to spit VB
and moving to C# doesn't change the fact that there is now a different way
to do the same things. Albeit, in some cases, it seems more cumbersome.
You do gain the fact that now, VB sits squarely in the same arena that C++
does. Granted the two may have different applications, they are now more
closely considered equals than ever before.

Have you seen what Microsoft has done to VB in .Net 2005? The certainly
demonstrated that VB was very much a viable solution in the software
development arena. Moving to VB.Net is more than an enhancement in feature
set, it is an opening to options that we didn't have (yes, even with all the
api at our disposal.)

Anyone assuming that a direct port from VB 6, to VB.Net of any production
application is sorely misguided. This is old news, we have known that there
were significant changes as early as 2001, back when we had 6 years until VB
of the old died.

The brightest side of this is that you have the lessons learned of a legacy
system. You have a code base to defer to. You do not have to rely so much
on "Subject Matter Experts" or "Business Users". All of your critical
decision trees are completed.

You still have a year before VB of the old goes under. It seems to me that
your legacy system is working in production and, barring the advent of the
latest computer plague, will continue to function when left unmarred for
some time yet. You are not completely pinned to a wall, even this late in
the game.

You may find yourself creating a more disparate system until the conversion
process is complete. Don't be afraid of that change, embrace the fact that
you are no longer solely supporting an existing system and that you now have
the ability "If I had it to do all it all over again". Knowing that you
might have to come out of your comfort zone, should be exhilarating to you
as a developer.

VB hasn't let us down, it merely graduated from high school.

I apologize for the diatribe, I just get frustrated with all the doomsday
talk when, yet another VB programmer first treads into the vast
possibilities of the next generation. Sheesh, on release day of 2005,
people were already bashing Microsoft ("The necessary evil, that it is") for
one reason or another. One size does not fit all, make of it as you will or
make your own.


Dave said:
VB6 to VB.NET - not impossible, but nearly :(

should prolly throw it all away start over and do it in C#

don't want to be the one to tell management that their millions of dollars
in software investment is a throw away though


AMDRIT said:
It doesn't appear so. Perhaps, you can create your own control that derives
from the listview that will implement this technology and then it will be
"automatic"

public class MyListViewItem
inherits ListViewItem
public property CompareType as Type
end Property
end Class

Public class MyListView
inherits ListView

event OnColumnClicked(object, MyColumnClickEventArgs)

Public Shadows Property Item(index as integer) as MyListViewItem
End Property

private sub ColumnClicked(object, ColumnClickEventArgs)
dim MyColumnClickEventArgs as ColumnClickEventArgs
raiseevent oncolumnclicked(me, temparg)
if not temparg.handled then
'perform customsort
end if
end sub

end Class

This implements manual sorting. Is there such thing as automatic where
you
just specify the column and the sort order ?



Use the ListViewItemSorter
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindows
formslistviewclasslistviewitemsortertopic.htm



Private Sub ColumnClick(ByVal o As Object, ByVal e As
ColumnClickEventArgs)
' Set the ListViewItemSorter property to a new ListViewItemComparer
object.
Me.listView1.ListViewItemSorter = New ListViewItemComparer(e.Column)
' Call the sort method to manually sort the column based on the
ListViewItemComparer implementation.
listView1.Sort()
End Sub

' Implements the manual sorting of items by columns.
Class ListViewItemComparer
Implements IComparer

Private col As Integer

Public Sub New()
col = 0
End Sub

Public Sub New(ByVal column As Integer)
col = column
End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer _
Implements IComparer.Compare
Return [String].Compare(CType(x,
ListViewItem).SubItems(col).Text,
CType(y, ListViewItem).SubItems(col).Text)
End Function
End Class




VB6 has a SorkKey property that you can setup on the ListView
control
to
tell the ListView what column to use for sorting. In .NET there is
a
Sort()
method and a SortOrder property that you can use to manipulate the
Sorting
property. My question is how do I perform the same functionality
as I
do
in VB6 setting the SortKey and SortOrder with the ListView.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top