Parse XML and populate in List Box

前端 未结 2 1371
星月不相逢
星月不相逢 2021-01-07 13:03

I\'m a newbie to C#.

I want to develop C# List box in Windows Form. I found this link to be helpful. But the input to the List box will be an XML of th

2条回答
  •  时光说笑
    2021-01-07 13:26

    You could use Linq to XML to do it like this.

    XDocument xmldoc = XDocument.Load(xmlStream);
    var items = (from i in xmldoc.Descendants("item")
                 select new { Item = i.Element("SEL").Value, Value = i.Element("VALUE").Value }).ToList();
    
    listBox1.DataSource = items;
    listBox1.DisplayMember = "Item";
    listBox1.ValueMember = "Value";
    

提交回复
热议问题