VB.NET - ListView control question

Associate
Joined
20 Feb 2004
Posts
250
Hi
I'm a bit stuck with the ListView control (in detailed mode). I have a table with three columns. Rows are selectable (not multi). I want to, -

1) return the value of the bit of text in the second column of the selected row. I know ListViewControlName.SelectedItems(0).Text gives the data in the first column, but what about the second?
2) Is it possible to sort the control by the second column? If so how?

Many thanks!
 
myListview.SelectedItems[0].SubItems[1].Text

Something like that I believe.

Sorting, I'm not sure, as I only ever use Virtual Mode.
 
Not sorted columns in .NET so not sure of the code. I do have it in VB6 that you should be able to convert with little head ache.
Code:
Private Sub lvwData_ColumnClick(Index As Integer, ByVal ColumnHeader As MSComctlLib.ColumnHeader)
Dim iLast, iCur As Integer

    With lvwData(Index)
        .Sorted = True
        If .SortOrder = lvwAscending Then
            .SortOrder = lvwDescending
        Else
            .SortOrder = lvwAscending
        End If
        iCur = ColumnHeader.Index - 1
        If iCur = iLast Then
            .Sorted = IIf(.Sorted = 1, 0, 1)
        End If
        .SortKey = iCur
        iLast = iCur
    End With
End Sub
Hope this helps.

TrUz
 
One more question, whats the best way to empty a ListView? I use the code below but I'm sure there is a more fficient call, just cant find it!

For Each removeStock In StockList.Items
StockList.Items.Remove(removeStock)
Next
 
Back
Top Bottom