Skip to content

How to get the sub-item text of the selected item in the list view in WPF? #7430

Answered by miloush
VahidEra asked this question in Q&A
Discussion options

You must be logged in to vote

Okay so your data, as the error already suggests, comes from an anonymous type:

        lis.Items.Add(New With {Key .name = "Jack", Key .address = "3240 Vernon Street"})
        lis.Items.Add(New With {Key .name = "Mary", Key .address = "3729 Cambridge Place"})

The lis.SelectedItem will contain the same objects you put in, not a "DataRowView". If you make up a type on the go as you did, it will be an anonymous type. You cannot access its members without Option Strict Off (or reflection).

A better option is to declare your type ahead of time:

Class MyRowData
    Public Property name As String
    Public Property address As String
End Class

Class MainWindow
    Private Sub MainWindow_Loade…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@VahidEra
Comment options

Comment options

You must be logged in to vote
1 reply
@VahidEra
Comment options

Answer selected by VahidEra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants