List of variables(XML) in combo box C# [duplicate]




This question already has an answer here:




I don't know how to get my variables into a combo box. I've done some research, it seems like a list to store these in is a perfect container for the elements, but getting the list to work is a different story.


Anyway, here's the code I'm using :



private List<string> HNames = new List<string>();
// ^ This is stored above `InitializeComponent();`

void LoadXML()
{
string path = "Mods//handling4.meta";
var doc = XDocument.Load(path);
var items = doc.Descendants("HandlingData").Elements("Item");
var query = from x in items

select new
{
HandlingName = (string)x.Element("handlingName"),
HandlingType = (string)x.Element("HandlingType"),
Mass = (decimal?)x.Element("fMass").Attribute("value"),
InitialDragCoeff = (decimal?)x.Element("fInitialDragCoeff").Attribute("value"),
PercentSubmerged = (decimal?)x.Element("fPercentSubmerged").Attribute("value"),
DriveBiasFront = (decimal?)x.Element("fDriveBiasFront").Attribute("value"),
InitialDriveGears = x.Element("nInitialDriveGears").Attribute("value"),
InitialDriveForce = (decimal?)x.Element("fInitialDriveForce").Attribute("value"),
DriveInertia = (decimal?)x.Element("fDriveInertia").Attribute("value")
};
foreach(var item in query)
{
HNames.Add(item.HandlingName);
}
}
private void button2_Click(object sender, EventArgs e)
{
comboBox1.Items.Add( HNames);
}


The problem is that now I'm seeing the word 'Collection' within my comboBox after clicking the button, rather than the actual handling names.


So my question is : How to use a list of variables within a comboBox ?


Further info: I'm new to programming! This is a windows form API, written in C#


Any help or guidance on this would be appreciated, if you could comment some keywords that I should Google that's helpful, if you understand the question & can produce a working answer that's also very helpful. I've been researching for hours, must be missing something


No comments:

Post a Comment