Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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# 来自其他控件的渲染。因此,最后我需要将listview中的数据存储到xml文件中。通过遍历列表视图的内容我们可以存储。但是有什么linqtoxml方法可以做到这一点吗?它显示了一个错误,比如找不到源类型“System.Windows.Forms.ListV_C#_Xml_Listview_File Io_Linq To Xml - Fatal编程技术网

C# 来自其他控件的渲染。因此,最后我需要将listview中的数据存储到xml文件中。通过遍历列表视图的内容我们可以存储。但是有什么linqtoxml方法可以做到这一点吗?它显示了一个错误,比如找不到源类型“System.Windows.Forms.ListV

C# 来自其他控件的渲染。因此,最后我需要将listview中的数据存储到xml文件中。通过遍历列表视图的内容我们可以存储。但是有什么linqtoxml方法可以做到这一点吗?它显示了一个错误,比如找不到源类型“System.Windows.Forms.ListV,c#,xml,listview,file-io,linq-to-xml,C#,Xml,Listview,File Io,Linq To Xml,来自其他控件的渲染。因此,最后我需要将listview中的数据存储到xml文件中。通过遍历列表视图的内容我们可以存储。但是有什么linqtoxml方法可以做到这一点吗?它显示了一个错误,比如找不到源类型“System.Windows.Forms.ListView.ListViewItemCollection”的查询模式的实现选择“未找到”。考虑显式指定范围变量“item”的类型。我使用'.NETFramework 3.5Grand, ListVIEWITMeCopys< /Cord>实现了 IL


来自其他控件的渲染。因此,最后我需要将
listview
中的数据存储到
xml
文件中。通过遍历
列表视图的内容
我们可以存储。但是有什么
linqtoxml
方法可以做到这一点吗?它显示了一个错误,比如
找不到源类型“System.Windows.Forms.ListView.ListViewItemCollection”的查询模式的实现选择“未找到”。考虑显式指定范围变量“item”的类型。我使用'.NETFramework 3.5Grand, ListVIEWITMeCopys< /Cord>实现了 ILIST和 iCeababy,所以应该没有问题。你是否有必要
使用System.Linq在你模块的某个地方?@Frédéric Hamidi,是的。。。这就是我们不能这样做的原因。否则我们必须使用
Cast()
方法,我想我明白了。我们可能需要使用。我将更新我的答案。它显示了一个错误,如
找不到源类型“System.Windows.Forms.ListView.ListViewItemCollection”的查询模式的实现选择“未找到”。考虑显式指定范围变量“item”的类型。我使用'.NETFramework 3.5Grand, ListVIEWITMeCopys< /Cord>实现了 ILIST和 iCeababy,所以应该没有问题。你是否有必要
使用System.Linq在你模块的某个地方?@Frédéric Hamidi,是的。。。这就是我们不能这样做的原因。否则我们必须使用
Cast()
方法,我想我明白了。我们可能需要使用。我会更新我的答案。
<root>
 <Child Name ="A1" val1="1" val2="0"/>
 <Child Name ="A2" val1="1" val2="2"/>
 <Child Name ="A3" val1="1" val2="3"/>
 <Child Name ="A4" val1="1" val2="4"/>
 <Child Name ="A5" val1="1" val2="5"/>
 <Child Name ="A6" val1="6" val2="0"/>
 <Child Name ="A7" val1="7" val2="0"/>
</root>
XDocument XD=new XDocument(new XElement("root",........// what i have to do here.......
XDocument document = new XDocument(new XElement("root",
    from item in yourListView.Items.Cast<ListViewItem>()
    select new XElement("Child",
        item.SubItems.Cast<ListViewSubItem>()
            .Select((subitem, i) => new XAttribute(
                i == 0 ? "Name" : yourListView.Columns[i].Text.ToLower(),
                subItem.Text)))));
public static bool ExportListViewlToXML(ListView listview, String filePath, String fileName)
    {
        FileStream fileStream;
        StreamWriter streamWriter;
        XmlTextWriter xmlTextWriter;

        try
        {
            // overwrite even if it already exists
            fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);

            streamWriter = new StreamWriter(fileStream);
            xmlTextWriter = new XmlTextWriter(streamWriter);
            xmlTextWriter.Formatting = Formatting.Indented;
            xmlTextWriter.WriteStartDocument();
            xmlTextWriter.WriteStartElement("Items");

            const int SUBITEM1_POS = 0;
            const int SUBITEM2_POS = 1;
            const int SUBITEM3_POS = 2;

            for (int i = 0; i < listview.Items.Count; i++)
            {
                String currentSubItem1 = listview.Items[i].SubItems[SUBITEM1_POS].Text;
                String currentSubItem2 = listview.Items[i].SubItems[SUBITEM2_POS].Text;
                String currentSubItem3 = listview.Items[i].SubItems[SUBITEM3_POS].Text;

                xmlTextWriter.WriteStartElement("Item");
                xmlTextWriter.WriteAttributeString("subitem1", currentSubItem1.ToString());
                xmlTextWriter.WriteAttributeString("subitem2", currentSubItem2.ToString());
                xmlTextWriter.WriteAttributeString("subitem3", currentSubItem3.ToString());
                xmlTextWriter.WriteEndElement();
            }

            xmlTextWriter.WriteEndDocument();
            xmlTextWriter.Flush();
            xmlTextWriter.Close();

            return true;
        }
        catch (IOException ex)
        {
            // do something about your error
            return false;
        }
    }