vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
List of "Klasse mit Controls" 
Autor: CAM-Andi
Datum: 06.02.14 06:51

Hallo, ich muss eine List of sortieren. Es soll nach "meinLabel.Text" sortiert werden.
'die List of definieren
Dim OpListItemContol As New List(Of Link_Label)
 
'Klassendefinition
Public Class Link_Label
    Private _meinPicbox As PictureBox
    Private _meinLabel As Label
    Public Property meinPicbox() As PictureBox
        Get
            Return _meinPicbox
        End Get
        Set(ByVal Value As PictureBox)
            _meinPicbox = Value
        End Set
    End Property
    Public Property meinLabel() As Label
        Get
            Return _meinLabel
        End Get
        Set(ByVal Value As Label)
            _meinLabel = Value
        End Set
    End Property
    Public Sub New()
    End Sub
End Class
 
'Sortierung
OpListItemContol.Sort(New Comparer(Of Link_Label)("meinLabel", False))
 
'Comparer-Klasse
Public Class Comparer(Of T)
    Implements IComparer(Of T)
 
    Private _sortProperties() As Reflection.PropertyInfo
    Private _sortDescendings() As Boolean
 
    Public Sub New(ByVal sortFieldName As String, ByVal sortDescending As _
      Boolean)
        ReDim _sortProperties(0)
        ReDim _sortDescendings(0)
        _sortProperties(0) = GetType(T).GetProperty(sortFieldName)
        _sortDescendings(0) = sortDescending
    End Sub
 
    Public Sub New(ByVal sortFieldNames() As String, ByVal sortDescendings() As _
    Boolean)
        If sortFieldNames.Length <> sortDescendings.Length Then Throw New  _
       System.Exception("Invalid parameters")
 
        ReDim _sortProperties(sortFieldNames.Length - 1)
        Dim i As Integer = 0
        For Each sfn As String In sortFieldNames
            _sortProperties(i) = GetType(T).GetProperty(sfn)
            i += 1
        Next
        _sortDescendings = sortDescendings
    End Sub
 
    Public Function Compare(ByVal x As T, ByVal y As T) As Integer Implements _
          System.Collections.Generic.IComparer(Of T).Compare
 
        Dim res As Integer
        Dim sortDescending As Boolean
        Dim i As Integer = 0
        For Each sortProperty In _sortProperties
            sortDescending = _sortDescendings(i)
            i += 1
            Dim Wert1 As IComparable = CType(sortProperty.GetValue(x, Nothing), _
              IComparable)
            Dim Wert2 As Object = sortProperty.GetValue(y, Nothing)
            res = Wert1.CompareTo(Wert2)
            If res <> 0 Then Exit For
        Next
        If sortDescending Then Return -res
        Return res
    End Function
End Class
In der Zeile
Dim Wert1 As IComparable = CType(sortProperty.GetValue(x, Nothing), IComparable)
bekomme ich eine InvalidCastExceptions: Das Objekt des Typs "System.Windows.Forms.Label" kann nicht in Typ "System.IComparable" umgewandelt werden. Wie bekomme ich Zugriff auf meinLabel.Text? Oder ist mein Ansatz falsch?

Grüße Andi

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
List of "Klasse mit Controls"1.454CAM-Andi06.02.14 06:51
Re: List of "Klasse mit Controls"1.009Christoph197206.02.14 07:02
Re: List of "Klasse mit Controls"1.008Manfred X06.02.14 07:52
Re: List of "Klasse mit Controls"1.062CAM-Andi06.02.14 09:07
Re: List of "Klasse mit Controls"976ErfinderDesRades06.02.14 15:40
Re: List of "Klasse mit Controls"982Christoph197206.02.14 17:46
Re: List of "Klasse mit Controls"994CAM-Andi06.02.14 18:54
Re: List of "Klasse mit Controls"1.006ErfinderDesRades06.02.14 19:11
Re: List of "Klasse mit Controls"1.038CAM-Andi06.02.14 19:31
Re: List of "Klasse mit Controls"996ErfinderDesRades06.02.14 22:07
Re: List of "Klasse mit Controls"981CAM-Andi07.02.14 11:08

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel