Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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# 如何从listBox1中的选定项向listBox2填充(添加项)?_C#_Xml_Listbox - Fatal编程技术网

C# 如何从listBox1中的选定项向listBox2填充(添加项)?

C# 如何从listBox1中的选定项向listBox2填充(添加项)?,c#,xml,listbox,C#,Xml,Listbox,我的任务是找出在listBox1中选择项目时,如何用相关的元素值填充第二个列表框。listBox1中的项目是相关(按属性值)元素的串联值 我有以下XML: <ServiceHistoryArray> <RecordID>XD116067*401529</RecordID> <SWR> <V Idx="1">7932</V><V Idx="2">7932</V><V

我的任务是找出在listBox1中选择项目时,如何用相关的
元素值填充第二个列表框。listBox1中的项目是相关(按属性值)元素的串联值

我有以下XML:

<ServiceHistoryArray>
    <RecordID>XD116067*401529</RecordID>
    <SWR>
        <V Idx="1">7932</V><V Idx="2">7932</V><V Idx="3">7932</V><V Idx="4">7932</V>
    </SWR>
    <Comments/>
    <Mileage>6</Mileage>
    <Operation>
        <V Idx="1">Z7000*WPDIP****PRE-DELIVERY INSPECTION - BASE TIME</V><V Idx="2">Z911*INC****ETCH WINDOWS</V><V Idx="3">B0048*WPBS4****FASCIA, FRONT BUMPER - REPLACE ONE PIECE</V><V Idx="4">9997*WPBS4****</V>
    </Operation>
    <CloseDate>1998-12-30</CloseDate>
    <OpenDate>1998-10-16</OpenDate>
    <PartsAmount>
        <V Idx="1">0.00</V><V Idx="2">0.00</V><V Idx="3">166.32</V><V Idx="4">0.00</V>
    </PartsAmount>
    <LaborAmount>
        <V Idx="1">64.80</V><V Idx="2">3.60</V><V Idx="3">140.40</V>
    </LaborAmount>
    <Warranty>
        <S Idx="1">&#xfc;96&#xfc;0&#xfd;&#xfd;10232632&#xfc;4H&#xfc;1</S><S Idx="2">&#xfc;96&#xfc;0&#xfd;&#xfd;10232632&#xfc;4H&#xfc;1</S><S Idx="3">&#xfc;96&#xfc;0&#xfd;&#xfd;10232632&#xfc;4H&#xfc;1</S>
    </Warranty>
</ServiceHistoryArray>  
澄清:

LINQ查询获取所有相关(按属性值)的
元素,将它们连接到一行中,并将它们添加到listBox1中

当在listBox1中选择相关(按属性值)项时,我需要让listBox2显示相应的
元素

如果需要进一步的澄清或信息,请告知

2013年7月29日:还没有点击。我的问题中是否遗漏了一些需要帮助的内容?

如果您将“V”更改为“S”@N4TKD将“V”更改为“S”,您指的是名为queryDetail的LINQ查询吗?如果是这样的话,这将简单地用元素填充第一个列表框。
//  Linq query to find all service history line items
var queryDetail = from v in xdoc.Descendants("V")
            group v by (int)v.Attribute("Idx") into g
            select String.Join(" ", g.Select(x => (string)x));

//  Iterates through the linq query and populates listBox1 with the servcie history details
foreach (string serviceInfo in queryDetail)
{
    listBox1.Items.Add(serviceInfo);
}