Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据用户选择填充列表框 我用C#来做这件事_C#_Xml - Fatal编程技术网

根据用户选择填充列表框 我用C#来做这件事

根据用户选择填充列表框 我用C#来做这件事,c#,xml,C#,Xml,好的,这就是我的XML文件的样子。。。只有更多的节点 <Recordset> <AUCCars> <Web_Series>5 Series</Web_Series> <Body_Desc>Sedan</Body_Desc> <Model_Type>550i (E60)</Model_Type> <Model_Year>2006<

好的,这就是我的XML文件的样子。。。只有更多的节点

<Recordset>
<AUCCars>
    <Web_Series>5 Series</Web_Series>
        <Body_Desc>Sedan</Body_Desc>
        <Model_Type>550i (E60)</Model_Type>
        <Model_Year>2006</Model_Year>
        <Ext_Colour>Alpine White III - Non-Metallic</Ext_Colour>
        <Int_Colour>Leather Dakota Black - Dakota Leather</Int_Colour>
        <Price>R 579000</Price>
        <Search_Price>579000</Search_Price>
        <Province>Gauteng</Province>
        <AucID>106288</AucID>
        <DealerID>45</DealerID>
        <DealerCode>29968</DealerCode>
        <DealerName>Lyndhurst Auto</DealerName>
        <Transmission>Automatic</Transmission>
        <AirCon>n/a</AirCon>
        <Radio>Yes</Radio>
        <PSteering>Yes</PSteering>
        <ABS>Yes</ABS>
        <Airbag>Yes</Airbag>
        <Sunroof>Yes</Sunroof>
        <Km>11500</Km>
        <Motorplan>Yes</Motorplan>
        <Warranty>N</Warranty>
        <BodyNo>6CR76051</BodyNo>
        <ModelOEM>NB52</ModelOEM>
        <ColourOEM>300</ColourOEM>
        <TrimOEM>LCSW</TrimOEM>
        <WheelsOEM></WheelsOEM>
        <Sold>N</Sold>
        <Notes> </Notes>
        <Moreoptions>Automatic Transmission with Steptronic
                     Interior trim finishers, Fine-wood, Poplar Grain Brown, high-gloss
                     Park Distance Control (PDC),front and rear</Moreoptions>
        <Picture>\Vehicle_Pictures\E60\LI\frontview_big_P0300.jpg</Picture>
        <PictureRear>\Vehicle_Pictures\E60\LI\rearview_big_P0300.jpg</PictureRear>
        <Interior>\Vehicle_Pictures\E60\LI\Interior\big_Fo_LCSW.jpg</Interior>
</AUCCars>
<AUCCars>
        <Web_Series>5 Series</Web_Series>
        <Body_Desc>Sedan</Body_Desc>
        <Model_Type>550i (E60)</Model_Type>
        <Model_Year>2006</Model_Year>
        <Ext_Colour>Black Sapphire - Metallic</Ext_Colour>
        <Int_Colour>Amethyst Black Exclusive Leather - Exclusive Leather</Int_Colour>
        <Price>R 529990</Price>
        <Search_Price>529990</Search_Price>
        <Province>KwaZulu Natal</Province>
        <AucID>111922</AucID>
        <DealerID>17</DealerID>
        <DealerCode>2485</DealerCode>
        <DealerName>Supertech</DealerName>
        <Transmission>Automatic</Transmission>
        <AirCon> Yes</AirCon>
        <Radio>Yes</Radio>
        <PSteering>Yes</PSteering>
        <ABS>Yes</ABS>
        <Airbag>Yes</Airbag>
        <Sunroof>n/a</Sunroof>
        <Km>7000</Km>
        <Motorplan>n/a</Motorplan>
        <Warranty>N</Warranty>
        <BodyNo>6CR75567</BodyNo>
        <ModelOEM>NB52</ModelOEM>
        <ColourOEM>475</ColourOEM>
        <TrimOEM>LDRH</TrimOEM>
        <WheelsOEM></WheelsOEM>
        <Sold>N</Sold>
        <Notes> </Notes>
        <Moreoptions>Automatic Transmission with Steptronic
                     Electric Rear Screen Roller Sun Blind with manual Side Blinds
                     Interior trim finishers, Fine-wood, Poplar Grain Brown, high-gloss
                     High Beam Assist
                     Head-up display (not with SA354)</Moreoptions>
        <Picture>\Vehicle_Pictures\E60\LI\frontview_big_P0475.jpg</Picture>
        <PictureRear>\Vehicle_Pictures\E60\LI\rearview_big_P0475.jpg</PictureRear>
        <Interior>\Vehicle_Pictures\E60\LI\Interior\big_Fo_LDRH.jpg</Interior>  
</AUCCars>
<Recordset>

5系列
轿车
550i(E60)
2006
阿尔卑斯白III-非金属
皮革达科他黑色-达科他皮革
R 579000
579000
豪登省
106288
45
29968
林德赫斯特汽车公司
自动的
不适用
对
对
对
对
对
11500
对
N
6CR76051
NB52
300
LCSW
N
带Steptronic的自动变速器
内饰饰面,优质木材,杨木颗粒棕色,高光泽
前后驻车距离控制(PDC)
\车辆图片\E60\LI\frontview\u big\u P0300.jpg
\车辆图片\E60\LI\rearview\u big\u P0300.jpg
\车辆图片\E60\LI\Interior\big\Fo\u LCSW.jpg
5系列
轿车
550i(E60)
2006
黑色蓝宝石-金属
紫水晶黑专用皮革-专用皮革
R 529990
529990
纳塔尔省
111922
17
2485
超科
自动的
对
对
对
对
对
不适用
7000
不适用
N
6CR75567
NB52
475
LDRH
N
带Steptronic的自动变速器
带手动侧百叶窗的电动后挡风卷帘遮阳帘
内饰饰面,优质木材,杨木颗粒棕色,高光泽
远光灯辅助
平视显示器(不适用于SA354)
\车辆图片\E60\LI\frontview\u big\u P0475.jpg
\车辆图片\E60\LI\review\u big\u P0475.jpg
\车辆图片\E60\LI\Interior\big\u Fo\u LDRH.jpg
  • 我需要填写系列、型号和年份的组合框

  • 这个我说对了。当我编译程序时,它会将所有系列加载到系列中
  • 组合框
  • 当我选择一个系列时,它会自动将所有模型加载到模型组合中
  • 盒子。当我选择一个模型时,它会相应地自动加载年份

  • 现在我需要根据选择显示数据

  • 我为系列组合框选择了“5系列”,为型号组合框11选择了“550i(E60)”。框,以及“2006”年组合框

  • 如何根据我的选择显示该特定节点中的所有数据13。在列表框中

  • 我希望我没把你弄错。。。我创建了一个小样本表单。在组合框的已选择索引更改的上,我将显示已过滤的aucCars。组合框根据问题中给定的详细信息从xml文件中获取数据
    (网络系列、车型类型、车型年份-不同)


    showaucars()
    I中,根据组合框中的选择进行过滤,并在列表框中显示结果。如果您想在列表框中显示特定元素,请添加一个新的linq stmt并选择相应的元素

    谢谢您的时间!这正是我想要的!很高兴我能帮助——作为回报,你可以考虑把我的答案投上来,或者把我的回答标记为最佳答案/解决方案!
    // get data from file
    XElement aucCars = XElement.Load("data.xml");
    private void cmbSeries_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cmbSeries.SelectedItem != null)
        {
            string currentSeries = cmbSeries.SelectedItem.ToString();
            var models = (from a in aucCars.Elements()
                            where a.Element("Web_Series").Value == currentSeries
                            select a.Element("Model_Type").Value).Distinct().ToList();
            cmbModel.DataSource = models;
        }
        showAucCars();
    }
    private void cmbModel_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (cmbModel.SelectedItem != null)
        {
            string currentSeries = cmbSeries.SelectedItem.ToString();
            string currentModel = cmbModel.SelectedItem.ToString();
    
            var years = (from a in aucCars.Elements()
                            where a.Element("Web_Series").Value == currentSeries &&
                            a.Element("Model_Type").Value == currentModel
                            select a.Element("Model_Year").Value).Distinct().ToList();
            cmbYear.DataSource = years;
        }
        showAucCars();
    }
    private void cmbYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        showAucCars();
    }
    private void frmXmlLoad_Load(object sender, EventArgs e)
    {            
        var series = (from a in aucCars.Elements()
                    select a.Element("Web_Series").Value).Distinct().ToList();
        cmbSeries.DataSource = series;
    }
    private void showAucCars()
    {
        var filterCars = aucCars.Elements();
        if (cmbSeries.SelectedItem!=null)
        {
            string currentSeries = cmbSeries.SelectedItem.ToString();
            filterCars = from a in filterCars
                            where a.Element("Web_Series").Value == currentSeries
                            select a;
        }
        if (cmbSeries.SelectedItem != null)
        {
            string currentModel = cmbModel.SelectedItem.ToString();
            filterCars = from a in filterCars
                            where a.Element("Model_Type").Value == currentModel
                            select a;
        }
        if (cmbSeries.SelectedItem != null)
        {
            string currentYear = cmbYear.SelectedItem.ToString();
            filterCars = from a in filterCars
                            where a.Element("Model_Year").Value == currentYear
                            select a;
        }
        // will show all the element data 
        // add a new linq stmt to select specific elements
        listBox1.DataSource = filterCars.ToList();            
    }