Bind listbox from a list of object inside an object

Viewed 6055

Here is a sample of 2 lists of Listing (tmp1 & tmp2) that are added to Data. Eventually this listbox will end up inside of a DataRepeater.

    Dim Data As New List(Of Test)

    Dim item As Test
    item = New Test       

    Dim tmp1 As New List(Of Listing)
    tmp1.Add(New Listing With {.ListingID = "004432", .Name = "Pizza Hut"})
    tmp1.Add(New Listing With {.ListingID = "024235", .Name = "Houston Pizza"})
    item.Listings.AddRange(tmp1)

    Data.Add(item)

    item = New Test

    Dim tmp2 As New List(Of Listing)
    tmp2.Add(New Listing With {.ListingID = "004432", .Name = "Pizza Hut"})
    tmp2.Add(New Listing With {.ListingID = "024235", .Name = "Houston Pizza"})
    item.Listings.AddRange(tmp2)

    Data.Add(item)

    Dim bs As New BindingSource
    bs.DataSource = Data

    ListBox1.DataSource = bs
    ListBox1.DisplayMember = "Listings.Listing.Name" ' I've tried many variations.

I've also tried:

    ListBox1.DataBindings.Add(New Binding("DisplayMember", bs, "Name"))
    ListBox1.DataBindings.Add(New Binding("DisplayMember", Data, "Name"))
    ListBox1.DataBindings.Add(New Binding("Items", bs, "Name"))
    ListBox1.DataBindings.Add(New Binding("Items", Data, "Name"))

I've not been able to Google a similar scenario for a solution. Any ideas?

2 Answers
Related