473,324 Members | 2,268 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,324 software developers and data experts.

ListView Sorting by Column

Using VB.NET

I have a ListView with several columns.

Two columns contain integer values, while the remaining contain string
values.

I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.

If anyone could offer some useful code, or suggestions as how this can
best be accomplished, it would be much appreciated.

Regards,

Owen
Nov 19 '05 #1
19 25388
It's actually quite difficult, in the fact that you need to create your own
sorting class.

Please check out this URL:

http://support.microsoft.com/default...;EN-US;Q319401

<WatchForWrapping()>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:a0********************************@4ax.com...
Using VB.NET

I have a ListView with several columns.

Two columns contain integer values, while the remaining contain string
values.

I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.

If anyone could offer some useful code, or suggestions as how this can
best be accomplished, it would be much appreciated.

Regards,

Owen

Nov 19 '05 #2
Thnak you for your suggestions Tom. I will try this out and let you
know how things turned out.

A little more difficult than VS6.

Thanks again,

Owen

On Thu, 21 Aug 2003 17:38:45 +0100, "Tom Spink"
<th**********@ntlworld.com> wrote:
It's actually quite difficult, in the fact that you need to create your own
sorting class.

Please check out this URL:

http://support.microsoft.com/default...;EN-US;Q319401

<WatchForWrapping()>


Nov 19 '05 #3
Tom,
It's actually quite difficult, in the fact that you need to create your own sorting class. Difficult? Or did you mean 'not difficult'?

IMHO although you need your own sorting class its actually very easy to
do...

For the VB.NET version of the article:
http://support.microsoft.com/default...b;EN-US;319399

Just a thought
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uk*************@tk2msftngp13.phx.gbl... It's actually quite difficult, in the fact that you need to create your own sorting class.

Please check out this URL:

http://support.microsoft.com/default...;EN-US;Q319401

<WatchForWrapping()>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:a0********************************@4ax.com...
Using VB.NET

I have a ListView with several columns.

Two columns contain integer values, while the remaining contain string
values.

I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.

If anyone could offer some useful code, or suggestions as how this can
best be accomplished, it would be much appreciated.

Regards,

Owen


Nov 19 '05 #4
Thanks Jay,

This will save me having to read and work with multiple languages.

Regards,

Owen

On Thu, 21 Aug 2003 11:47:28 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja********@email.msn.com> wrote:
Tom,
It's actually quite difficult, in the fact that you need to create your

own
sorting class.

Difficult? Or did you mean 'not difficult'?

IMHO although you need your own sorting class its actually very easy to
do...

For the VB.NET version of the article:
http://support.microsoft.com/default...b;EN-US;319399

Just a thought
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uk*************@tk2msftngp13.phx.gbl...
It's actually quite difficult, in the fact that you need to create your

own
sorting class.

Please check out this URL:

http://support.microsoft.com/default...;EN-US;Q319401

<WatchForWrapping()>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:a0********************************@4ax.com...
> Using VB.NET
>
> I have a ListView with several columns.
>
> Two columns contain integer values, while the remaining contain string
> values.
>
> I am confused as to how I would provide functionality to sort columns
> based on the column header the user has clicked in both Ascending and
> Descending formats.
>
> If anyone could offer some useful code, or suggestions as how this can
> best be accomplished, it would be much appreciated.
>
> Regards,
>
> Owen



Nov 19 '05 #5
I only came across that article today, because I've been doing it today :-)

I thought it was a bit long winded. Not 'difficult'. Wrong choice of words
<g>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
Tom,
It's actually quite difficult, in the fact that you need to create your

own
sorting class.

Difficult? Or did you mean 'not difficult'?

IMHO although you need your own sorting class its actually very easy to
do...

For the VB.NET version of the article:
http://support.microsoft.com/default...b;EN-US;319399

Just a thought
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uk*************@tk2msftngp13.phx.gbl...
It's actually quite difficult, in the fact that you need to create your

own
sorting class.

Please check out this URL:

http://support.microsoft.com/default...;EN-US;Q319401

<WatchForWrapping()>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:a0********************************@4ax.com...
Using VB.NET

I have a ListView with several columns.

Two columns contain integer values, while the remaining contain string
values.

I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.

If anyone could offer some useful code, or suggestions as how this can best be accomplished, it would be much appreciated.

Regards,

Owen



Nov 19 '05 #6
Tom,

I think you're correct in saying this is a bit long winded, when
compared to doing the same in VS6.

Owen

On Thu, 21 Aug 2003 17:58:24 +0100, "Tom Spink"
<th**********@ntlworld.com> wrote:
I only came across that article today, because I've been doing it today :-)

I thought it was a bit long winded. Not 'difficult'. Wrong choice of words
<g>


Nov 19 '05 #7
Tom,
I'll give you long winded ;-)

IMHO this is part of the flexibility of OOP... The extra complexity
(indirection) is what gives you the flexibility.

The IComparer interface is actually used in a number of places in .NET. For
example you can use it with Array.Sort & ArrayList.Sort to enable sorting a
collection of objects based on different attributes of the contained
objects. Objects themselves can implement the IComparable interface to allow
the object itself to know how to compare itself with another object. Again
Array.Sort & ArrayList.Sort can sort objects that implement IComparable, if
you do not give them a IComparer object...

Array.Sort only needs to care about IComparer & IComparable. The objects
themselves are enabled to compare each other...

Hope this helps
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
I only came across that article today, because I've been doing it today :-)
I thought it was a bit long winded. Not 'difficult'. Wrong choice of words
<g>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:eg**************@TK2MSFTNGP10.phx.gbl...
Tom,
It's actually quite difficult, in the fact that you need to create your
own
sorting class. Difficult? Or did you mean 'not difficult'?

IMHO although you need your own sorting class its actually very easy to
do...

For the VB.NET version of the article:
http://support.microsoft.com/default...b;EN-US;319399

Just a thought
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uk*************@tk2msftngp13.phx.gbl...
It's actually quite difficult, in the fact that you need to create
your
own
sorting class.

Please check out this URL:

http://support.microsoft.com/default...;EN-US;Q319401

<WatchForWrapping()>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:a0********************************@4ax.com...
> Using VB.NET
>
> I have a ListView with several columns.
>
> Two columns contain integer values, while the remaining contain

string > values.
>
> I am confused as to how I would provide functionality to sort columns > based on the column header the user has clicked in both Ascending and > Descending formats.
>
> If anyone could offer some useful code, or suggestions as how this

can best be accomplished, it would be much appreciated.
>
> Regards,
>
> Owen



Nov 19 '05 #8
Hi, I'm aware of where it's used, and I also appreciate OOP and it's
flexibility. I also enjoy complexity, I'm not actually complaining, however,
people who have started VB.NET and had no previous experience of true OOP
may find it daunting.

I also know about IComparable.

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uz**************@TK2MSFTNGP09.phx.gbl...
Tom,
I'll give you long winded ;-)

IMHO this is part of the flexibility of OOP... The extra complexity
(indirection) is what gives you the flexibility.

The IComparer interface is actually used in a number of places in .NET. For example you can use it with Array.Sort & ArrayList.Sort to enable sorting a collection of objects based on different attributes of the contained
objects. Objects themselves can implement the IComparable interface to allow the object itself to know how to compare itself with another object. Again
Array.Sort & ArrayList.Sort can sort objects that implement IComparable, if you do not give them a IComparer object...

Array.Sort only needs to care about IComparer & IComparable. The objects
themselves are enabled to compare each other...

Hope this helps
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
I only came across that article today, because I've been doing it today

:-)

I thought it was a bit long winded. Not 'difficult'. Wrong choice of words
<g>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:eg**************@TK2MSFTNGP10.phx.gbl...
Tom,
> It's actually quite difficult, in the fact that you need to create

your own
> sorting class.
Difficult? Or did you mean 'not difficult'?

IMHO although you need your own sorting class its actually very easy to do...

For the VB.NET version of the article:
http://support.microsoft.com/default...b;EN-US;319399

Just a thought
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uk*************@tk2msftngp13.phx.gbl...
> It's actually quite difficult, in the fact that you need to create your own
> sorting class.
>
> Please check out this URL:
>
> http://support.microsoft.com/default...;EN-US;Q319401
>
> <WatchForWrapping()>
>
> --
> Happy to help,
> -- Tom Spink
> (th**********@ntlworld.com)
>
> "Go down with your server"
>
> http://dotnetx.betasafe.com >> On The Mend
>
> Please respond to the newsgroup,
> so all can benefit
>
>
> "Owen T. Soroke" <ow*********@hotmail.com> wrote in message
> news:a0********************************@4ax.com...
> > Using VB.NET
> >
> > I have a ListView with several columns.
> >
> > Two columns contain integer values, while the remaining contain string > > values.
> >
> > I am confused as to how I would provide functionality to sort columns > > based on the column header the user has clicked in both Ascending and > > Descending formats.
> >
> > If anyone could offer some useful code, or suggestions as how this

can
> > best be accomplished, it would be much appreciated.
> >
> > Regards,
> >
> > Owen
>
>



Nov 19 '05 #9
Hello,

"Owen T. Soroke" <ow*********@hotmail.com> schrieb:
I have a ListView with several columns.

Two columns contain integer values, while the remaining contain string
values.

I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.


C#, but maybe it points you into the right direction:

http://www.codeproject.com/cs/miscct...edlistview.asp

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #10
Thank you Herfried.

This was exactly what I was looking to accomplish. I will now begin
attempting to make this code relevant to my project.

Best Regards,

Owen T. Soroke

On Thu, 21 Aug 2003 19:48:14 +0200, "Herfried K. Wagner [MVP]"
<hi*******@m.activevb.de> wrote:
Hello,

"Owen T. Soroke" <ow*********@hotmail.com> schrieb:
I have a ListView with several columns.

Two columns contain integer values, while the remaining contain string
values.

I am confused as to how I would provide functionality to sort columns
based on the column header the user has clicked in both Ascending and
Descending formats.


C#, but maybe it points you into the right direction:

http://www.codeproject.com/cs/miscct...edlistview.asp

HTH,
Herfried K. Wagner


Nov 19 '05 #11
Tom,
I've seen your name (here) enough, I'm figured you already knew.

It was included for Owen & lurkers more then you specifically.

Its one of those: do I give the 1 liner and you don't know. Or give the
dissertation and you do know. ;-)

Later
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi, I'm aware of where it's used, and I also appreciate OOP and it's
flexibility. I also enjoy complexity, I'm not actually complaining, however, people who have started VB.NET and had no previous experience of true OOP
may find it daunting.

I also know about IComparable.

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:uz**************@TK2MSFTNGP09.phx.gbl...
Tom,
I'll give you long winded ;-)

IMHO this is part of the flexibility of OOP... The extra complexity
(indirection) is what gives you the flexibility.

The IComparer interface is actually used in a number of places in .NET. For
example you can use it with Array.Sort & ArrayList.Sort to enable sorting a
collection of objects based on different attributes of the contained
objects. Objects themselves can implement the IComparable interface to

allow
the object itself to know how to compare itself with another object. Again Array.Sort & ArrayList.Sort can sort objects that implement IComparable,

if
you do not give them a IComparer object...

Array.Sort only needs to care about IComparer & IComparable. The objects
themselves are enabled to compare each other...

Hope this helps
Jay

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
I only came across that article today, because I've been doing it
today :-)

I thought it was a bit long winded. Not 'difficult'. Wrong choice of words <g>

--
Happy to help,
-- Tom Spink
(th**********@ntlworld.com)

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:eg**************@TK2MSFTNGP10.phx.gbl...
> Tom,
> > It's actually quite difficult, in the fact that you need to create

your
> own
> > sorting class.
> Difficult? Or did you mean 'not difficult'?
>
> IMHO although you need your own sorting class its actually very easy to > do...
>
> For the VB.NET version of the article:
> http://support.microsoft.com/default...b;EN-US;319399
>
> Just a thought
> Jay
>
> "Tom Spink" <th**********@ntlworld.com> wrote in message
> news:uk*************@tk2msftngp13.phx.gbl...
> > It's actually quite difficult, in the fact that you need to create

your
> own
> > sorting class.
> >
> > Please check out this URL:
> >
> > http://support.microsoft.com/default...;EN-US;Q319401
> >
> > <WatchForWrapping()>
> >
> > --
> > Happy to help,
> > -- Tom Spink
> > (th**********@ntlworld.com)
> >
> > "Go down with your server"
> >
> > http://dotnetx.betasafe.com >> On The Mend
> >
> > Please respond to the newsgroup,
> > so all can benefit
> >
> >
> > "Owen T. Soroke" <ow*********@hotmail.com> wrote in message
> > news:a0********************************@4ax.com...
> > > Using VB.NET
> > >
> > > I have a ListView with several columns.
> > >
> > > Two columns contain integer values, while the remaining contain

string
> > > values.
> > >
> > > I am confused as to how I would provide functionality to sort

columns
> > > based on the column header the user has clicked in both

Ascending and
> > > Descending formats.
> > >
> > > If anyone could offer some useful code, or suggestions as how
this can

> > > best be accomplished, it would be much appreciated.
> > >
> > > Regards,
> > >
> > > Owen
> >
> >
>
>



Nov 19 '05 #12
Owen,
The ListViewColumnSorter class provides that ability (item #8 in the
article).

Actually the following line:
' Compare the two items.
compareResult =
ObjectCompare.Compare(listviewX.SubItems(ColumnToS ort).Text,
listviewY.SubItems(ColumnToSort).Text)

The ObjectCompare.Compare call does the actual comparisons.

CaseInsensitiveComparer is one of those objects that knows about IComparable
that I mentioned in my other post. The CaseInsensitiveComparer.Compare
method accepts objects, to it is able to compare other object types. All the
normal .NET data types (Byte, Short, Integer, Long, Single, Double, Decimal,
String, DateTime) implement IComparable, so the CaseInsensitiveComparer
object can compare them.

Hope this helps
Jay

"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:u1********************************@4ax.com...
Jay, Tom,

You example previously provided from the MSDN resources includes the
following code:

Dim columnheader As ColumnHeader ' Used for creating column
headers.
Dim listviewitem As ListViewItem ' Used for creating ListView
items.

' Make sure that the view is set to show details.
ListView1.View = View.Details

' Create some ListView items consisting of first and last names.
listviewitem = New ListViewItem("Mike")
listviewitem.SubItems.Add("Nash")
Me.ListView1.Items.Add(listviewitem)

listviewitem = New ListViewItem("Kim")
listviewitem.SubItems.Add("Abercrombie")
Me.ListView1.Items.Add(listviewitem)

listviewitem = New ListViewItem("Sunil")
listviewitem.SubItems.Add("Koduri")
Me.ListView1.Items.Add(listviewitem)

listviewitem = New ListViewItem("Birgit")
listviewitem.SubItems.Add("Seidl")
Me.ListView1.Items.Add(listviewitem)

' Create some column headers for the data.
columnheader = New ColumnHeader()
columnheader.Text = "First Name"
Me.ListView1.Columns.Add(columnheader)

columnheader = New ColumnHeader()
columnheader.Text = "Last Name"
Me.ListView1.Columns.Add(columnheader)

' Loop through and size each column header to fit the column header
text.
For Each columnheader In Me.ListView1.Columns
columnheader.Width = -2
Next

How would you include the ability to sort additional data types
including integer and date/time types using similar code included
above.

Regards,

Owen

<<snip>>
Nov 19 '05 #13
Cor
Hi Owen,
I did change a litte bit the Microsoft example, because that does not sort
decimals in a value order but in a string order.
This is VB and not C#
It sorts dates, strings and values

Private Sub lsv_ColumnClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles lsv.ColumnClick
lsv.BeginUpdate()
If e.Column <> sortColumn Then
sortColumn = e.Column
lsv.Sorting = SortOrder.Ascending
Else
If lsv.Sorting = SortOrder.Ascending Then
lsv.Sorting = SortOrder.Descending
Else
lsv.Sorting = SortOrder.Ascending
End If
End If
lsv.Sort()
lsv.ListViewItemSorter = New clsListViewSorter(e.Column,
lsv.Sorting)
lsv.EndUpdate()
End Sub

Option Strict On
Imports System.Globalization
Public Class clsListViewSorter
Implements IComparer
Private col As Integer
Private order As SortOrder

Public Sub New()
col = 0
order = SortOrder.Ascending
End Sub

Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
col = column
Me.order = order
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements System.Collections.IComparer.Compare
Dim returnVal As Integer

Try
Dim firstDate As System.DateTime = DateTime.Parse(CType(x,
ListViewItem).SubItems(col).Text)
Dim secondDate As System.DateTime = DateTime.Parse(CType(y,
ListViewItem).SubItems(col).Text)
returnVal = DateTime.Compare(firstDate, secondDate)
Catch
Try
Dim myComparer As New Comparer(New
CultureInfo(CultureInfo.CurrentCulture.ToString, False))
Dim a As Object = Int64.Parse(CType(x,
ListViewItem).SubItems(col).Text)
Dim b As Object = Int64.Parse(CType(y,
ListViewItem).SubItems(col).Text)
returnVal = myComparer.Compare(a, b)
Catch
returnVal = [String].Compare(CType(x,
ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
End Try
End Try
If order = SortOrder.Descending Then
returnVal *= -1
End If
Return returnVal
End Function
End Class
Nov 19 '05 #14
Good Morning,

I have been able to implement the column sorting code in VB.NET and
have one more question, if I can draw on your expertise.

I am trying to add arrows representing the current position of the
columns as they are sorted. I have tried using ASCII 30 & 31, and 129,
130 & 53, 54 with no luck.

VB.NET seems to display these characters incorrectly.

------- = --------

Example:

' determine what the last sort order was and change it

If lvwIndex.Sorting = SortOrder.Ascending Then
lvwIndex.Sorting = SortOrder.Descending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(53)

Else
lvwIndex.Sorting = SortOrder.Ascending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(54)

End if

------- = --------

I have read some C++ and C# code which has the system draw the arrow.
Other than that, I have had no success in finding an easier solution.

Thank you for your prervious suggestions, I hope you can help me with
this one.

Regards,

Owen

On Fri, 22 Aug 2003 13:46:46 +0200, "Cor" <no*@non.com> wrote:
Hi Owen,
I did change a litte bit the Microsoft example, because that does not sort
decimals in a value order but in a string order.
This is VB and not C#
It sorts dates, strings and values

Private Sub lsv_ColumnClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles lsv.ColumnClick
lsv.BeginUpdate()
If e.Column <> sortColumn Then
sortColumn = e.Column
lsv.Sorting = SortOrder.Ascending
Else
If lsv.Sorting = SortOrder.Ascending Then
lsv.Sorting = SortOrder.Descending
Else
lsv.Sorting = SortOrder.Ascending
End If
End If
lsv.Sort()
lsv.ListViewItemSorter = New clsListViewSorter(e.Column,
lsv.Sorting)
lsv.EndUpdate()
End Sub

Option Strict On
Imports System.Globalization
Public Class clsListViewSorter
Implements IComparer
Private col As Integer
Private order As SortOrder

Public Sub New()
col = 0
order = SortOrder.Ascending
End Sub

Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
col = column
Me.order = order
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements System.Collections.IComparer.Compare
Dim returnVal As Integer

Try
Dim firstDate As System.DateTime = DateTime.Parse(CType(x,
ListViewItem).SubItems(col).Text)
Dim secondDate As System.DateTime = DateTime.Parse(CType(y,
ListViewItem).SubItems(col).Text)
returnVal = DateTime.Compare(firstDate, secondDate)
Catch
Try
Dim myComparer As New Comparer(New
CultureInfo(CultureInfo.CurrentCulture.ToString , False))
Dim a As Object = Int64.Parse(CType(x,
ListViewItem).SubItems(col).Text)
Dim b As Object = Int64.Parse(CType(y,
ListViewItem).SubItems(col).Text)
returnVal = myComparer.Compare(a, b)
Catch
returnVal = [String].Compare(CType(x,
ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text)
End Try
End Try
If order = SortOrder.Descending Then
returnVal *= -1
End If
Return returnVal
End Function
End Class


Nov 19 '05 #15
Own,
I would consider using one of the Unicode characters, for example: U+25BC
Black Down-Pointing Triangle & U+25B2 Black Up=Pointing Triangle instead. I
used Character Map to find the characters.

Then its a matter of ensuring the font you are using supports those
characters, which means that Win98 & Win ME may not support the Unicode
character. Arial supports the characters, Microsoft Sans Serif (the default)
does not.

Hope this helps
Jay

"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:5v********************************@4ax.com...
Good Morning,

I have been able to implement the column sorting code in VB.NET and
have one more question, if I can draw on your expertise.

I am trying to add arrows representing the current position of the
columns as they are sorted. I have tried using ASCII 30 & 31, and 129,
130 & 53, 54 with no luck.

VB.NET seems to display these characters incorrectly.

------- = --------

Example:

' determine what the last sort order was and change it

If lvwIndex.Sorting = SortOrder.Ascending Then
lvwIndex.Sorting = SortOrder.Descending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(53)

Else
lvwIndex.Sorting = SortOrder.Ascending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(54)

End if

------- = --------

I have read some C++ and C# code which has the system draw the arrow.
Other than that, I have had no success in finding an easier solution.

Thank you for your prervious suggestions, I hope you can help me with
this one.

Regards,

Owen

On Fri, 22 Aug 2003 13:46:46 +0200, "Cor" <no*@non.com> wrote:
Hi Owen,
I did change a litte bit the Microsoft example, because that does not sortdecimals in a value order but in a string order.
This is VB and not C#
It sorts dates, strings and values

Private Sub lsv_ColumnClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles lsv.ColumnClick
lsv.BeginUpdate()
If e.Column <> sortColumn Then
sortColumn = e.Column
lsv.Sorting = SortOrder.Ascending
Else
If lsv.Sorting = SortOrder.Ascending Then
lsv.Sorting = SortOrder.Descending
Else
lsv.Sorting = SortOrder.Ascending
End If
End If
lsv.Sort()
lsv.ListViewItemSorter = New clsListViewSorter(e.Column,
lsv.Sorting)
lsv.EndUpdate()
End Sub

Option Strict On
Imports System.Globalization
Public Class clsListViewSorter
Implements IComparer
Private col As Integer
Private order As SortOrder

Public Sub New()
col = 0
order = SortOrder.Ascending
End Sub

Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
col = column
Me.order = order
End Sub
Public Function Compare(ByVal x As Object, ByVal y As Object) As IntegerImplements System.Collections.IComparer.Compare
Dim returnVal As Integer

Try
Dim firstDate As System.DateTime = DateTime.Parse(CType(x,
ListViewItem).SubItems(col).Text)
Dim secondDate As System.DateTime = DateTime.Parse(CType(y,
ListViewItem).SubItems(col).Text)
returnVal = DateTime.Compare(firstDate, secondDate)
Catch
Try
Dim myComparer As New Comparer(New
CultureInfo(CultureInfo.CurrentCulture.ToString , False))
Dim a As Object = Int64.Parse(CType(x,
ListViewItem).SubItems(col).Text)
Dim b As Object = Int64.Parse(CType(y,
ListViewItem).SubItems(col).Text)
returnVal = myComparer.Compare(a, b)
Catch
returnVal = [String].Compare(CType(x,
ListViewItem).SubItems(col).Text, CType(y, ListViewItem).SubItems(col).Text) End Try
End Try
If order = SortOrder.Descending Then
returnVal *= -1
End If
Return returnVal
End Function
End Class

Nov 19 '05 #16
Thanks for your response Jay:

When issuing a unicode value to display, I have tried using the
Char.GetUnicodeCategory(). This isn't working.

How can I display these unicode values in VB.NET code?

Thanks,

Owen

On Fri, 22 Aug 2003 13:32:13 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja********@email.msn.com> wrote:
Own,
I would consider using one of the Unicode characters, for example: U+25BC
Black Down-Pointing Triangle & U+25B2 Black Up=Pointing Triangle instead. I
used Character Map to find the characters.

Then its a matter of ensuring the font you are using supports those
characters, which means that Win98 & Win ME may not support the Unicode
character. Arial supports the characters, Microsoft Sans Serif (the default)
does not.

Hope this helps
Jay

"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:5v********************************@4ax.com.. .
Good Morning,

I have been able to implement the column sorting code in VB.NET and
have one more question, if I can draw on your expertise.

I am trying to add arrows representing the current position of the
columns as they are sorted. I have tried using ASCII 30 & 31, and 129,
130 & 53, 54 with no luck.

VB.NET seems to display these characters incorrectly.

------- = --------

Example:

' determine what the last sort order was and change it

If lvwIndex.Sorting = SortOrder.Ascending Then
lvwIndex.Sorting = SortOrder.Descending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(53)

Else
lvwIndex.Sorting = SortOrder.Ascending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(54)

End if

------- = --------

I have read some C++ and C# code which has the system draw the arrow.
Other than that, I have had no success in finding an easier solution.

Thank you for your prervious suggestions, I hope you can help me with
this one.

Regards,

Owen

On Fri, 22 Aug 2003 13:46:46 +0200, "Cor" <no*@non.com> wrote:
>Hi Owen,
>I did change a litte bit the Microsoft example, because that does notsort >decimals in a value order but in a string order.
>This is VB and not C#
>It sorts dates, strings and values
>
> Private Sub lsv_ColumnClick(ByVal sender As Object, ByVal e As
>System.Windows.Forms.ColumnClickEventArgs) Handles lsv.ColumnClick
> lsv.BeginUpdate()
> If e.Column <> sortColumn Then
> sortColumn = e.Column
> lsv.Sorting = SortOrder.Ascending
> Else
> If lsv.Sorting = SortOrder.Ascending Then
> lsv.Sorting = SortOrder.Descending
> Else
> lsv.Sorting = SortOrder.Ascending
> End If
> End If
> lsv.Sort()
> lsv.ListViewItemSorter = New clsListViewSorter(e.Column,
>lsv.Sorting)
> lsv.EndUpdate()
> End Sub
>
>
>
>Option Strict On
>Imports System.Globalization
>Public Class clsListViewSorter
> Implements IComparer
> Private col As Integer
> Private order As SortOrder
>
> Public Sub New()
> col = 0
> order = SortOrder.Ascending
> End Sub
>
> Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
> col = column
> Me.order = order
> End Sub
>
>
> Public Function Compare(ByVal x As Object, ByVal y As Object) AsInteger >Implements System.Collections.IComparer.Compare
> Dim returnVal As Integer
>
> Try
> Dim firstDate As System.DateTime = DateTime.Parse(CType(x,
>ListViewItem).SubItems(col).Text)
> Dim secondDate As System.DateTime = DateTime.Parse(CType(y,
>ListViewItem).SubItems(col).Text)
> returnVal = DateTime.Compare(firstDate, secondDate)
> Catch
> Try
> Dim myComparer As New Comparer(New
>CultureInfo(CultureInfo.CurrentCulture.ToString , False))
> Dim a As Object = Int64.Parse(CType(x,
>ListViewItem).SubItems(col).Text)
> Dim b As Object = Int64.Parse(CType(y,
>ListViewItem).SubItems(col).Text)
> returnVal = myComparer.Compare(a, b)
> Catch
> returnVal = [String].Compare(CType(x,
>ListViewItem).SubItems(col).Text, CType(y,ListViewItem).SubItems(col).Text) > End Try
> End Try
> If order = SortOrder.Descending Then
> returnVal *= -1
> End If
> Return returnVal
> End Function
>
>
>End Class
>


Nov 19 '05 #17
Jay, Tom, Herfried.... Thanks once again.

As requested, this is the article that has been posted. It believe it
is written in C++.

-------------------------- ========= ------------------------

The list view control does not provide any visual feedback on whether
the list is sorted.

To give feedback to the users, we can use the owner draw feature of
the header control and display a triangle pointing downwards or
pointing updwards, indicating whether the list is sorted in the
ascending or the descending order.

This, of course, is applicable only if the list view control is in the
report view mode.

Since we have to use an owner drawn header control, we will need to
derive a class from CHeaderCtrl and add the functionality in this
class. Here are the steps involved.
Step 1: Derive class from CHeaderCtrl

If you don't have a class derived from CHeaderCtrl, derive one now.
You can use the Class Wizard to create one for you. I used the name
CMyHeaderCtrl for the derived class.

Step 2: Add member variables

Add member variables in CMyHeaderCtrl to track the column that is
sorted and the sorting order. These variables are declared as
protected members and we will provide a function to set them.
protected:
int m_nSortCol;
BOOL m_bSortAsc;

Step 3: Initialize the variables in the constructor

Initialize the m_nSortCol variable to -1 in the constructor. This
indicates that the list is not sorted.
CMyHeaderCtrl:: CMyHeaderCtrl()
{
m_nSortCol = -1;
}

Step 4: Add function SetSortImage()

Add a function SetSortImage() to the CMyHeaderCtrl class. This is the
function that will be used to set the sort indicator. The
SetSortImage() function takes the column number as an argument and
also a boolean value to indicate whether it is sorted in the ascending
order or in the descending order.

After setting the internal variables, the function set the header item
to owner drawn. This will ensure that the DrawItem() function will get
called. The function then invalidates the header control so that any
previous sort indicator is removed and the new one is displayed.
int CMyHeaderCtrl::SetSortImage( int nCol, BOOL bAsc )
{
int nPrevCol = m_nSortCol;

m_nSortCol = nCol;
m_bSortAsc = bAsc;

// Change the item to ownder drawn
HD_ITEM hditem;

hditem.mask = HDI_FORMAT;
GetItem( nCol, &hditem );
hditem.fmt |= HDF_OWNERDRAW;
SetItem( nCol, &hditem );

// Invalidate header control so that it gets redrawn
Invalidate();
return nPrevCol;
}

Step 5: Override DrawItem()

The DrawItem() is where the sort indicator actually gets drawn.
Besides drawing the sort triangle, this function is now also
responsible for drawing the column label itself. The DrawItem()
function is called for each item in the header control that has the
HDF_OWNERDRAW format.

These are the step we take in the DrawItem() function to draw the
column label and the triangular image to indicate the sort order:

1. Attach the device context handle passed in through the
argument to a CDC object for easier device context handling. The
handle is detached from the CDC object before the function returns. If
we did not detach the handle then the DC would be released when the
CDC object is destroyed.

2. We save the DC and change the clipping region so that all the
updates are contrained within the header item for which the DrawItem()
function is called. The device context is restored before the function
returns.

3. We compute the offset used when drawing the label and the sort
triangle. The offset is used to leave a margin around the label and is
equal to twice the width of a space character.

4. We determine the format to be used when drawing the column
label. Since the column label can be aligned left, center or right, we
have to choose an appropriate format for the DrawText() function. You
will also notice the flag DT_END_ELLIPSIS. This tells the DrawText()
function that if the text doesn't fit with the rectangle specified,
then the text should be shortened and three dots appended to the text
so that the result fits within the rectangle.

5. We next adjust the rectangle within which the label will be
drawn and then draw the lable using DrawText().

6. Finally we draw the triangle to indicate the sort order. We
use two different color to draw the triangle so that it matches the
other GUI elements in Widnows. The COLOR_3DHILIGHT color is used for
edges facing the light source, and the COLOR_3DSHADOW color is used
for the shadow.

void CMyHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
CDC dc;

dc.Attach( lpDrawItemStruct->hDC );

// Get the column rect
CRect rcLabel( lpDrawItemStruct->rcItem );

// Save DC
int nSavedDC = dc.SaveDC();

// Set clipping region to limit drawing within column
CRgn rgn;
rgn.CreateRectRgnIndirect( &rcLabel );
dc.SelectObject( &rgn );
rgn.DeleteObject();

// Draw the background
dc.FillRect(rcLabel, &CBrush(::GetSysColor(COLOR_3DFACE)));

// Labels are offset by a certain amount
// This offset is related to the width of a space character
int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2;
// Get the column text and format
TCHAR buf[256];
HD_ITEM hditem;

hditem.mask = HDI_TEXT | HDI_FORMAT;
hditem.pszText = buf;
hditem.cchTextMax = 255;

GetItem( lpDrawItemStruct->itemID, &hditem );

// Determine format for drawing column label
UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP
| DT_VCENTER |
DT_END_ELLIPSIS ;

if( hditem.fmt & HDF_CENTER)
uFormat |= DT_CENTER;
else if( hditem.fmt & HDF_RIGHT)
uFormat |= DT_RIGHT;
else
uFormat |= DT_LEFT;

// Adjust the rect if the mouse button is pressed on it
if( lpDrawItemStruct->itemState == ODS_SELECTED )
{
rcLabel.left++;
rcLabel.top += 2;
rcLabel.right++;
}

// Adjust the rect further if Sort arrow is to be displayed
if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
{
rcLabel.right -= 3 * offset;
}

rcLabel.left += offset;
rcLabel.right -= offset;

// Draw column label
if( rcLabel.left < rcLabel.right )
dc.DrawText(buf,-1,rcLabel, uFormat);

// Draw the Sort arrow
if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
{
CRect rcIcon( lpDrawItemStruct->rcItem );

// Set up pens to use for drawing the triangle
CPen penLight(PS_SOLID, 1,
GetSysColor(COLOR_3DHILIGHT));
CPen penShadow(PS_SOLID, 1,
GetSysColor(COLOR_3DSHADOW));
CPen *pOldPen = dc.SelectObject( &penLight );

if( m_bSortAsc )
{
// Draw triangle pointing upwards
dc.MoveTo( rcIcon.right - 2*offset, offset-1);
dc.LineTo( rcIcon.right - 3*offset/2,
rcIcon.bottom - offset );
dc.LineTo( rcIcon.right - 5*offset/2-2,
rcIcon.bottom - offset );
dc.MoveTo( rcIcon.right - 5*offset/2-1,
rcIcon.bottom - offset-1 );

dc.SelectObject( &penShadow );
dc.LineTo( rcIcon.right - 2*offset, offset-2);
}
else
{
// Draw triangle pointing downwords
dc.MoveTo( rcIcon.right - 3*offset/2,
offset-1);
dc.LineTo( rcIcon.right - 2*offset-1,
rcIcon.bottom - offset + 1 );
dc.MoveTo( rcIcon.right - 2*offset-1,
rcIcon.bottom - offset );

dc.SelectObject( &penShadow );
dc.LineTo( rcIcon.right - 5*offset/2-1, offset
-1 );
dc.LineTo( rcIcon.right - 3*offset/2, offset
-1);
}

// Restore the pen
dc.SelectObject( pOldPen );
}

// Restore dc
dc.RestoreDC( nSavedDC );

// Detach the dc before returning
dc.Detach();
}

Step 6: Add member variable for header control in list view class

Now that we are done with the CMyHeaderCtrl class, we have to add a
member to the CListCtrl or the CListView derived class so that we can
access the extended functionality. Add a protected member.
protected:

CMyHeaderCtrl m_headerctrl;

Step 7: Subclass the header control

We have to sub-class the header control so that the DrawItem()
function in CMyHeaderCtrl can get called. If you are using a CListView
derived class, you can place the sub-classing code in
OnInitialUpdate(). If you are using a CListCtrl derived class, then
put the code in PreSubclassWindow(). In either case, make sure you
call the base class version of the function before subclassing the
header control. If the listview control was not created in the report
view mode, then you have to change the style of control before trying
the subclass the control. You can use ModifyStyle() for this. The
reason why we need to change the style to the report view mode is that
the header control is created only when the control first taken to the
report view mode.

void CMyListCtrl::PreSubclassWindow()
{
CListCtrl::PreSubclassWindow();

// Add initialization code
m_headerctrl.SubclassWindow( ::GetDlgItem(m_hWnd,0) );
}

Step 8: Use SetSortImage() to indicate sort order

Now you are all set to add the sort order indicator. Whenever you sort
the list view control, call the CMyHeaderCtrl::SetSortImage() function
with the column number on which the list is sorted and the order of
sorting. E.g.

m_headerctrl.SetSortImage( nCol, bAscending );

-------------------------- ========= ------------------------

Hope you can help,

Regards,

Owen

On Fri, 22 Aug 2003 19:01:06 GMT, Owen T. Soroke
<ow*********@hotmail.com> wrote:
Thanks for your response Jay:

When issuing a unicode value to display, I have tried using the
Char.GetUnicodeCategory(). This isn't working.

How can I display these unicode values in VB.NET code?

Thanks,

Owen

On Fri, 22 Aug 2003 13:32:13 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja********@email.msn.com> wrote:
Own,
I would consider using one of the Unicode characters, for example: U+25BC
Black Down-Pointing Triangle & U+25B2 Black Up=Pointing Triangle instead. I
used Character Map to find the characters.

Then its a matter of ensuring the font you are using supports those
characters, which means that Win98 & Win ME may not support the Unicode
character. Arial supports the characters, Microsoft Sans Serif (the default)
does not.

Hope this helps
Jay

"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:5v********************************@4ax.com. ..
Good Morning,

I have been able to implement the column sorting code in VB.NET and
have one more question, if I can draw on your expertise.

I am trying to add arrows representing the current position of the
columns as they are sorted. I have tried using ASCII 30 & 31, and 129,
130 & 53, 54 with no luck.

VB.NET seems to display these characters incorrectly.

------- = --------

Example:

' determine what the last sort order was and change it

If lvwIndex.Sorting = SortOrder.Ascending Then
lvwIndex.Sorting = SortOrder.Descending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(53)

Else
lvwIndex.Sorting = SortOrder.Ascending
lvwIndex.Columns.Item(e.Column).Text =_
lvwIndex.Columns.Item(e.Column).Text & Chr(54)

End if

------- = --------

I have read some C++ and C# code which has the system draw the arrow.
Other than that, I have had no success in finding an easier solution.

Thank you for your prervious suggestions, I hope you can help me with
this one.

Regards,

Owen

On Fri, 22 Aug 2003 13:46:46 +0200, "Cor" <no*@non.com> wrote:

>Hi Owen,
>I did change a litte bit the Microsoft example, because that does not

sort
>decimals in a value order but in a string order.
>This is VB and not C#
>It sorts dates, strings and values
>
> Private Sub lsv_ColumnClick(ByVal sender As Object, ByVal e As
>System.Windows.Forms.ColumnClickEventArgs) Handles lsv.ColumnClick
> lsv.BeginUpdate()
> If e.Column <> sortColumn Then
> sortColumn = e.Column
> lsv.Sorting = SortOrder.Ascending
> Else
> If lsv.Sorting = SortOrder.Ascending Then
> lsv.Sorting = SortOrder.Descending
> Else
> lsv.Sorting = SortOrder.Ascending
> End If
> End If
> lsv.Sort()
> lsv.ListViewItemSorter = New clsListViewSorter(e.Column,
>lsv.Sorting)
> lsv.EndUpdate()
> End Sub
>
>
>
>Option Strict On
>Imports System.Globalization
>Public Class clsListViewSorter
> Implements IComparer
> Private col As Integer
> Private order As SortOrder
>
> Public Sub New()
> col = 0
> order = SortOrder.Ascending
> End Sub
>
> Public Sub New(ByVal column As Integer, ByVal order As SortOrder)
> col = column
> Me.order = order
> End Sub
>
>
> Public Function Compare(ByVal x As Object, ByVal y As Object) As

Integer
>Implements System.Collections.IComparer.Compare
> Dim returnVal As Integer
>
> Try
> Dim firstDate As System.DateTime = DateTime.Parse(CType(x,
>ListViewItem).SubItems(col).Text)
> Dim secondDate As System.DateTime = DateTime.Parse(CType(y,
>ListViewItem).SubItems(col).Text)
> returnVal = DateTime.Compare(firstDate, secondDate)
> Catch
> Try
> Dim myComparer As New Comparer(New
>CultureInfo(CultureInfo.CurrentCulture.ToString , False))
> Dim a As Object = Int64.Parse(CType(x,
>ListViewItem).SubItems(col).Text)
> Dim b As Object = Int64.Parse(CType(y,
>ListViewItem).SubItems(col).Text)
> returnVal = myComparer.Compare(a, b)
> Catch
> returnVal = [String].Compare(CType(x,
>ListViewItem).SubItems(col).Text, CType(y,

ListViewItem).SubItems(col).Text)
> End Try
> End Try
> If order = SortOrder.Descending Then
> returnVal *= -1
> End If
> Return returnVal
> End Function
>
>
>End Class
>


Nov 19 '05 #18
Owen,
The easiest way is to "type" the character into your source file! Again you
can use Character Map (Under Start - Programs - Accessories - System Tools)
to find the key sequence to be able to 'type' the character or I normally
just select, copy from Character Map, then paste into my source. Of course
with these characters follow the instructions that VS.NET gives you about
saving your source with encoding.

The other option is if you know the ordinal value of the character use ChrW
to convert the ordinal value to a Char.

Black Down-Pointing Triangle
lvwIndex.Columns.Item(e.Column).Text & ChrW(&H25BC)
Black Up-Pointing Triangle lvwIndex.Columns.Item(e.Column).Text & ChrW(&H25B2)

Note use ChrW to get Unicode characters, as Chr does a conversion based on
the code page for the current thread.

Hope this helps
Jay

"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:62********************************@4ax.com...
Thanks for your response Jay:

When issuing a unicode value to display, I have tried using the
Char.GetUnicodeCategory(). This isn't working.

How can I display these unicode values in VB.NET code?

Thanks,

Owen

On Fri, 22 Aug 2003 13:32:13 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja********@email.msn.com> wrote:
Own,
I would consider using one of the Unicode characters, for example: U+25BC
Black Down-Pointing Triangle & U+25B2 Black Up=Pointing Triangle instead.

Iused Character Map to find the characters.

Then its a matter of ensuring the font you are using supports those
characters, which means that Win98 & Win ME may not support the Unicode
character. Arial supports the characters, Microsoft Sans Serif (the default)does not.

Hope this helps
Jay

<<snip>>
Nov 19 '05 #19
Thanks Jay,

I will try the copy / paste solution to this question.

I am also looking at the possiblilty of having the system draw the
triangles for graphical display.

Failing that, I will use the Unicode character solution.

Regards,

Owen T. Soroke

On Fri, 22 Aug 2003 14:29:34 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja********@email.msn.com> wrote:
Owen,
The easiest way is to "type" the character into your source file! Again you
can use Character Map (Under Start - Programs - Accessories - System Tools)
to find the key sequence to be able to 'type' the character or I normally
just select, copy from Character Map, then paste into my source. Of course
with these characters follow the instructions that VS.NET gives you about
saving your source with encoding.

The other option is if you know the ordinal value of the character use ChrW
to convert the ordinal value to a Char.

Black Down-Pointing Triangle
>> lvwIndex.Columns.Item(e.Column).Text & ChrW(&H25BC)
Black Up-Pointing Triangle >> lvwIndex.Columns.Item(e.Column).Text & ChrW(&H25B2)
Note use ChrW to get Unicode characters, as Chr does a conversion based on
the code page for the current thread.

Hope this helps
Jay

"Owen T. Soroke" <ow*********@hotmail.com> wrote in message
news:62********************************@4ax.com.. .
Thanks for your response Jay:

When issuing a unicode value to display, I have tried using the
Char.GetUnicodeCategory(). This isn't working.

How can I display these unicode values in VB.NET code?

Thanks,

Owen

On Fri, 22 Aug 2003 13:32:13 -0500, "Jay B. Harlow [MVP - Outlook]"
<Ja********@email.msn.com> wrote:
>Own,
>I would consider using one of the Unicode characters, for example: U+25BC
>Black Down-Pointing Triangle & U+25B2 Black Up=Pointing Triangle instead.

I >used Character Map to find the characters.
>
>Then its a matter of ensuring the font you are using supports those
>characters, which means that Win98 & Win ME may not support the Unicode
>character. Arial supports the characters, Microsoft Sans Serif (thedefault) >does not.
>
>Hope this helps
>Jay
>

<<snip>>


Nov 19 '05 #20

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

Similar topics

0
by: rmorvay | last post by:
I have successfully integrated sorting in the listview control with the following code: Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As...
0
by: Abhishek | last post by:
Hi! I am using listview control having 4 columns. I want it to behave in a similar manner as the details view of windows explorer. i.e it should sort on all the columns and all the columns...
0
by: Abhishek | last post by:
Hi! I am using listview control containing 4 columns. I want it to behave in a similar manner as the details view of windows explorer. i.e it should sort on all the columns and all the columns...
1
by: Mamatha | last post by:
Hi I have one application ,that diplays data from database into the listview control.While adding data to the listview i want to display an icon to the leftside of the first column's data.Here...
3
by: Curtis | last post by:
I am trying to do a simple sort on a list view.With the listview control the first time I sort on the control it sorts the items but anytime after that it fails to sort. I'm sure this is a simple...
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...
2
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column...
11
by: Alan T | last post by:
Does the ListView supports sort? I want to have a up/down arrow/triangle that show it is sorted asc or desc on the column headers when I click the column header. May be I need a third-party...
2
by: win | last post by:
The SortKey of VB6 is not in .Net. Can I still do sorting using a listview? Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.