Thx
i populate the key property of each listitem with the unique id... then use
listview.selecteditem.key to get it
can't remember how to sort off the top of my head... the sdk has it... i
believe it's straightforward...
hope this helps
dushan bilbija
"Alexei Smirnov" <sma...@hotmail.com> wrote in message
news:#aZr46RmBHA.1644@tkmsftngp05...
Are you talking about .NET, or VB6? I know how to get it in VB6, but I need
it in new version.
reflex reply... that's vb6 talk
in vb.net i use the tag property of the item.
btw... the sorting question? not straightforward, but here's the code:
Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As
System.WinForms.ColumnClickEventArgs) Handles ListView1.ColumnClick
ListView1.Sorting = SortOrder.Ascending
Dim Sorter = New ListViewSorter(e.column)
ListView1.ListItemSorter = Sorter
End Sub
Public Class ListViewSorter
Implements System.Collections.IComparer
Public SortIndex As Integer
Public Sub New(ByVal SortIndex As Integer)
Me.SortIndex = SortIndex
End Sub
Public Function Compare_(ByVal x As Object, ByVal y As Object) As
Integer Implements System.Collections.IComparer.Compare
If SortIndex = 0 Then
Return String.Compare(x.text, y.text)
Else
Return String.Compare(x.GetSubItem(SortIndex - 1),
y.GetSubItem(SortIndex - 1))
End If
End Function
End Class
hope this helps
dushan bilbija
"Alexei Smirnov" <sma...@hotmail.com> wrote in message
news:ec4J9$amBHA.2012@tkmsftngp04...
thanks again for the answer, but it not helps me :-)
I saw somewhere already code you sent me, but when I copy it to my form, I
receive an error "ListView1.ListItemSorter private and can't be public" (or
something like this...). Maybe I made something wrong, but can you again
explain me, how to use this code? Should I copy "Class ListViewSorter" to
form body, or I need to create a new class?
Maybe it would be nice if you could sent me zip with your form, and I can
check where was my error.
thx,
Alexei
"Dushan Bilbija" <dbil...@email.msn.com> wrote in message
news:OEfmLWkmBHA.2212@tkmsftngp05...
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As ColumnHeader)
' When a ColumnHeader object is clicked, the ListView control is
' sorted by the subitems of that column.
' Set the SortKey to the Index of the ColumnHeader - 1
ListView1.SortKey = ColumnHeader.Index - 1
' Set Sorted to True to sort the list.
ListView1.Sorted = True
End Sub
For more information, please refer to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmctl198/ht
ml/vbprosortorderx.asp
Regards,
This posting is provided “AS IS”, with no warranties, and confers no
rights.
"Gary" <garyo...@microsoft.com> wrote in message
news:x7pA6mPnBHA.2216@cpmsftngxa07...
2. By default, we can only sort the the ListView control based on first
column as follows:
Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
'MessageBox.Show(e.Column.ToString())
'listview1.ListViewItemSorter=
If ListView1.Sorting = SortOrder.Descending Then
ListView1.Sorting = SortOrder.Ascending
ElseIf ListView1.Sorting = SortOrder.Ascending Then
ListView1.Sorting = SortOrder.Descending
End If
End Sub
To sort on the clicked column, you could create a class (that implements
the IComparer interface) to support column sorting in the ListView control.
If an instance of the class is assigned to the ListViewItemSorter property
and the Sort method is called, you can then create code in the event
handler for the ColumnClick event to perform sorting based on the column
that was clicked.