Reputation: 37
First off, I'm absolutely new to coding so this might be really trivial, but I couldn't find a solution for this anywhere.
So, I've already got an OpenFileDialog working. I can select the xml files just fine, and it also gives me the path to the selected file. The xml files that I'm talking about contain all sorts of stuff, but I only need to extract two elements from them (zip codes and their corresponding IDs). I've also already created a DataGridView, but I just can't figure out how to make the Grid display my elements. Also, only one xml file will be used at a time.
I'm really sorry about that stupid question, but I've been trying to get this working for hours now.
Upvotes: 1
Views: 282
Reputation: 1390
You might try to read xml to dataset
var xmlFile = XmlReader.Create("File.xml", new XmlReaderSettings());
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
and then bind needed values with the DataGridView:
YourDataGridView.DataSource = ds.Tables[0].Select(o => new
{
Column1 = o.SomeValue,
Column2 = o.SomeOtherValue
}).ToList();
Hope it helps
Upvotes: 2