473,395 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ListView SortKey


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
Jan 16 '06 #1
6 7266

Use the ListViewItemSorter

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemwindowsformslistviewclasslistviewitemso rtertopic.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" <Ki************@community.nospam> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...

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

Jan 16 '06 #2
This implements manual sorting. Is there such thing as automatic where you
just specify the column and the sort order ?
"AMDRIT" <am****@hotmail.com> wrote in message
news:uW**************@TK2MSFTNGP15.phx.gbl...

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" <Ki************@community.nospam> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...

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


Jan 16 '06 #3
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" <Ki************@community.nospam> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
This implements manual sorting. Is there such thing as automatic where
you
just specify the column and the sort order ?
"AMDRIT" <am****@hotmail.com> wrote in message
news:uW**************@TK2MSFTNGP15.phx.gbl...

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" <Ki************@community.nospam> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
>
> 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
>
>



Jan 16 '06 #4
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" <am****@hotmail.com> wrote in message
news:eB*************@TK2MSFTNGP10.phx.gbl...
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" <Ki************@community.nospam> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
This implements manual sorting. Is there such thing as automatic where
you
just specify the column and the sort order ?
"AMDRIT" <am****@hotmail.com> wrote in message
news:uW**************@TK2MSFTNGP15.phx.gbl...

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" <Ki************@community.nospam> wrote in message
news:ux**************@TK2MSFTNGP12.phx.gbl...
>
> 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
>
>



Jan 17 '06 #5
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" <Ki************@community.nospam> wrote in message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
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" <am****@hotmail.com> wrote in message
news:eB*************@TK2MSFTNGP10.phx.gbl...
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" <Ki************@community.nospam> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
> This implements manual sorting. Is there such thing as automatic where
> you
> just specify the column and the sort order ?
>
>
> "AMDRIT" <am****@hotmail.com> wrote in message
> news:uW**************@TK2MSFTNGP15.phx.gbl...
>>
>> 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" <Ki************@community.nospam> wrote in message
>> news:ux**************@TK2MSFTNGP12.phx.gbl...
>> >
>> > 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
>> >
>> >
>>
>>
>
>



Jan 17 '06 #6
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" <am****@hotmail.com> wrote in message
news:Op*************@TK2MSFTNGP09.phx.gbl...
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" <Ki************@community.nospam> wrote in message
news:eZ**************@TK2MSFTNGP11.phx.gbl...
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" <am****@hotmail.com> wrote in message
news:eB*************@TK2MSFTNGP10.phx.gbl...
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" <Ki************@community.nospam> wrote in message
news:OP**************@TK2MSFTNGP12.phx.gbl...
> This implements manual sorting. Is there such thing as automatic where > you
> just specify the column and the sort order ?
>
>
> "AMDRIT" <am****@hotmail.com> wrote in message
> news:uW**************@TK2MSFTNGP15.phx.gbl...
>>
>> 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" <Ki************@community.nospam> wrote in message
>> news:ux**************@TK2MSFTNGP12.phx.gbl...
>> >
>> > 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
>> >
>> >
>>
>>
>
>



Jan 17 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Lauwers | last post by:
I know you can edit the first column of the listview control, is there a way to edit the second and/or the other columns? greets John
8
by: Jon Ripley | last post by:
Using VB6 (for two weeks!) I could get a ListBox search working perfectly but with a ListView it has completely stumped me. I've not found any previous posts that have helped :( The user...
6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
0
by: Brad | last post by:
Hi everyone, I am trying to sort columns in a listview. When the user clicks on a column I want to sort on that column. The kicker is, I don't know how to trap for the column click for the...
2
by: Jan Driesen | last post by:
Hello, In Vb6, sorting a column of a listview is like this: Private Sub ListView1_ColumnClick(ByVal ColumnHeader As ComctlLib.ColumnHeader) Me.ListView1.SortKey = ColumnHeader.Index - 1 If...
1
by: Diarmuid | last post by:
How do I sort ListViews in vb.net? In VB6, I would have set the sortkey = columnheader, then set ListView1.Sorting But, theres no sortkey in the vb.net version. Thanks Diarmuid
6
by: Dave | last post by:
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...
6
by: Vbbeginner07 | last post by:
The following code is for sorting,but that works in a different format: Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader) With ListView1 '// change to the...
2
by: win | last post by:
The SortKey of VB6 is not in .Net. Can I still do sorting using a listview? Thanks
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.