WPF - binding Inside a collection

I'm looking to bind a specific element of a list.

Public Class itemCATIA

    Property l As New List(Of itemCATIAProperties) 'the list

   Sub New(d)
    For Each item As Parameter In pCATIA.UserRefProperties
                Dim myP As New itemCATIAProperties(item.Name, 
                 item.ValueAsString)
                l.Add(myP)  'the list
     Next
    end sub

end class

Public Class itemCATIAProperties

    Property Name As String
    Property Value As String

    Sub New(item As String, _value As String)
        Dim s() As String = Strings.Split(item, "\")
        Name = s(UBound(s))
        Value = _value
    End Sub
End Class

and below my tests to bind the correct value inside a dynamically created column :

 Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)

        Dim c As New DataGridTextColumn
        c.Header = "MASS"
        c.Binding = New Binding("l[Name='MASS'].Value") 'does not work
        c.Binding = New Binding("l[0].Value") 'does not return the good index of my list l. i want index=c.header
        MaDataGrid.Columns.Add(c)
    End Sub

Is there a method to retrieve the value whose index is the column header ?

Thanks a lot :)

1 answer

  • answered 2022-05-04 21:37 Disvoys

    Well i resolved with something not very beautiful.. if someone get a best solution, i take :)

    i replaced in the sub new() :

        Dim l_ As New List(Of itemCATIAProperties)
        For Each item As Parameter In pCATIA.UserRefProperties
            Dim myP As New itemCATIAProperties(item.Name, item.ValueAsString)
            l_.Add(myP)
        Next
    
        For i = 1 To 30
            l.Add(Nothing)
        Next
        For Each item In l_
            Select Case item.Name
                Case "MATERIAL"
                    l(0) = item
                Case "OBSERVATIONS"
                    l(1) = item
                Case "LENGTH"
                    l(2) = item
                Case "LENGTH"
                    l(3) = item
                Case "THICKNESS/DIAMETER"
                    l(5) = item
                Case "MASS"
                    l(5) = item
                Case "SUPPLIER"
                    l(6) = item
                Case "REF"
                    l(7) = item
                Case "TTS"
                    l(8) = item
                Case "SYM"
                    l(9) = item
                Case "NomPuls_Marquage"
                    l(10) = item
                Case "NomPuls_Traitement"
                    l(11) = item
                Case "NomPuls_Protection"
                    l(12) = item
                Case "NomPuls_Dim_Brutes"
                    l(13) = item
                Case "NomPuls_Masse"
                    l(14) = item
                Case "NomPuls_Matiere"
                    l(15) = item
                Case "NomPuls_Designation"
                    l(16) = item
                Case "NomPuls_Indice"
                    l(17) = item
                Case "NomPuls_Planche"
                    l(18) = item
                Case "DETAIL NUMBER"
                    l(19) = item
                Case "STOCK SIZE"
                    l(20) = item
            End Select
        Next
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum