如何匹配数据插入到我的ComboBox在C# [英] How can I match data to be inserted into my ComboBox in C#

查看:101
本文介绍了如何匹配数据插入到我的ComboBox在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<root>
    <Bathing>
        <Id>San100</Id>
        <name>Santoor</name>
        <AvailProducts>30</AvailProducts>
        <Cost>20.00</Cost>
    </Bathing>
    <Bathing>
        <Id>Det123</Id>
        <name>Dettol</name>
        <AvailProducts>30</AvailProducts>
        <Cost>15.00</Cost>
    </Bathing>
    <Bathing>
        <Id>Rex123</Id>
        <name>Rexona</name>
        <AvailProducts>30</AvailProducts>
        <Cost>16.00</Cost>
    </Bathing>
</root>

我是C#和XML的新用户。这里我使用XML作为数据表。

I am new to C# and XML. Here I am using XML as a data table.

如何只插入Name元素到我的 ComboBox

How can I insert only Name elements into my ComboBox?

推荐答案

创建一个数据集,然后通过数据集读取XML文件,然后将组合框绑定到dataset.Set显示成员为name。

Create a dataset and then read XML file through dataset and then bind combo box to dataset.Set display member to "name".

string myXMLfile = @"C:\MySchema.xml";
    DataSet ds = new DataSet();
    // Create new FileStream with which to read the schema.
    System.IO.FileStream fsReadXml = new System.IO.FileStream 
        (myXMLfile, System.IO.FileMode.Open);

        ds.ReadXml(fsReadXml);
        combobox1.DataSource = ds;
        combobox1.Displaymember="name";       

这篇关于如何匹配数据插入到我的ComboBox在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆