Ryan Walkowski
Ryan Walkowski

Reputation: 361

Populating ListBox with a List(T) Class. Not using datasource

I have the following list

static List<SectorBodies> MatchList = new List<SectorBodies>();

And it's associated class

public class SectorBodies
{
    public int MatchCount { get; set; }
    public string StringPosition { get; set; }

    public string SolarSystemFileComment { get; set; }
    public string SolarSystemX { get; set; }
    public string SolarSystemY { get; set; }
    public string SolarSystemZ { get; set; }

    public string OuterFileComment { get; set; }
    public string OuterOrbitX { get; set; }
    public string OuterOrbitY { get; set; }
    public string OuterOrbitZ { get; set; }
    public string OrbitName { get; set; }
    public string OrbitPrefab { get; set; }

    public string PlanetFileComment { get; set; }
    public string PlanetX { get; set; }
    public string PlanetY { get; set; }
    public string PlanetZ { get; set; }
    public string PlanetName { get; set; }
    public string PlanetBiome { get; set; }
    public string PlanetIsStart { get; set; }
}

The following is the watch list to give scope of whats inside enter image description here

I am trying to populate a ListBox with a list element named as OrbitName without using the datasource bind as I would prefer to do manipulation of the results before populating. I am aware of listBox1.Items.Add() but i cant seem to populate it properly it just populates the listbox with the namespace.class in my case Parser.SectorBodies. So how do i using the Items.Add method add all the OrbitName into the ListBox

Upvotes: 0

Views: 66

Answers (1)

BugFinder
BugFinder

Reputation: 17858

You could do

foreach(var item in MatchList) listbox1.Items.Add(item); listbox1.DisplayMember="OrbitName";

this will display the OrbitName for each item.

Upvotes: 1

Related Questions