Hallo,
folgendes Problem; ich lade mein ListView mittels:
verwende ich damit die Items in Colum 4 Absteigend Sortiert werden.
Meine Klasse zum Sortieren;
Aber beim Starten kommt immer der Fehler: InvalidArgument=Value mit dem Wert 4 ist für index ungültig. Parametername: index
Ich hab keine Ahnung woran das liegt
folgendes Problem; ich lade mein ListView mittels:
VB.NET-Quellcode
- Dim li As New ListViewItem
- Dim Filename As String
- Dim TFile As System.IO.StreamReader
- Dim sRGB As String()
- Dim S As String
- Dim X, Y As Integer
- Dim S1, S2, S3, S4, S5, S6, S7, S8, S9, S10 As String
- Try
- Filename = "F:\Mechaniker\MechanikerDB2017.lst"
- ListView1.Items.Clear()
- TFile = My.Computer.FileSystem.OpenTextFileReader(Filename)
- Do While (TFile.Peek() > -1)
- X = ListView1.Items.Count
- S = Trim(TFile.ReadLine)
- sRGB = S.Split(",")
- S1 = sRGB(0)
- S2 = sRGB(1)
- S3 = sRGB(2)
- S4 = sRGB(3)
- S5 = sRGB(4)
- S6 = sRGB(5)
- S7 = sRGB(6)
- S8 = sRGB(7)
- S9 = sRGB(8)
- S10 = sRGB(9)
- Dim item As ListViewItem = ListView1.Items.Add(S1)
- item.SubItems.Add(S2)
- item.SubItems.Add(S3)
- item.SubItems.Add(S4)
- item.SubItems.Add(S5)
- item.SubItems.Add(S6)
- item.SubItems.Add(S7)
- item.SubItems.Add(S8)
- item.SubItems.Add(S9)
- item.SubItems.Add(S10)
- item.ImageIndex = 1
- Loop
- Catch ex As Exception
- End Try
- li.Checked = True
- ToolStripStatusLabel2.Text = "Aufträge: " & ListView1.Items.Count.ToString
- TFile.Close()
- ListView1.Sort()
verwende ich damit die Items in Colum 4 Absteigend Sortiert werden.
Meine Klasse zum Sortieren;
VB.NET-Quellcode
- Public Class ListViewComparer
- Implements IComparer
- Private intColumn As Integer
- Private soSortOrder As SortOrder
- Private cicComparer As CaseInsensitiveComparer
- Public Sub New(ByVal ParentListView As ListView)
- intColumn = 4
- soSortOrder = SortOrder.Descending
- cicComparer = New CaseInsensitiveComparer()
- ParentListView.ListViewItemSorter = Me
- End Sub
- Public Property SortOrder() As SortOrder
- Get
- Return soSortOrder
- End Get
- Set(ByVal value As SortOrder)
- soSortOrder = value
- End Set
- End Property
- Public Property SortColumn() As Integer
- Get
- Return intColumn
- End Get
- Set(ByVal value As Integer)
- intColumn = value
- End Set
- End Property
- Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
- Dim compareResult As Integer
- Dim listviewX As ListViewItem, listviewY As ListViewItem
- listviewX = CType(x, ListViewItem)
- listviewY = CType(y, ListViewItem)
- compareResult = cicComparer.Compare(listviewX.SubItems(intColumn).Text, listviewY.SubItems(intColumn).Text)
- If soSortOrder = SortOrder.Ascending Then
- Return compareResult
- ElseIf soSortOrder = SortOrder.Descending Then
- Return compareResult * -1
- Else
- Return 0
- End If
- End Function
- End Class
Aber beim Starten kommt immer der Fehler: InvalidArgument=Value mit dem Wert 4 ist für index ungültig. Parametername: index
Ich hab keine Ahnung woran das liegt