简体   繁体   English

datagridview到xml文件vb.net

[英]datagridview to xml file vb.net

i really needs your kind of help. 我真的需要您的帮助。

i already done writing code from text box + button to create and write into xml file. 我已经完成了从文本框+按钮编写代码的操作,以创建并写入xml文件。 So now i try to apply the same details but using the datagridview (without textbox). 因此,现在我尝试应用相同的详细信息,但使用datagridview(无文本框)。

i'm still new and i really don't know how to apply the cell ,index and everythings about datagridview. 我仍然很新,我真的不知道如何应用单元格,索引以及有关datagridview的所有信息。

For example my details in TEXTBOX 1 as ID,TEXTBOX 2 as NAME so I transfer to DATAGRIDVIEW column(0) as ID,column(1) as NAME so everytime user key in the ID and NAME in every row the ID/NAME will goes to the XML file by clicking the button 例如,我在TEXTBOX 1中作为ID的详细信息,在TEXTBOX 2中作为NAME的详细信息,因此我将ID作为ID转移到DATAGRIDVIEW列(0),作为NAME转移至column(1),因此每当用户在ID和NAME的每行中键入ID / NAME时,单击按钮将其转换为XML文件

So i really need your help how to apply this things here is my code: 所以我真的需要您的帮助,如何在我的代码中应用这些东西:

<i>Dim settings As New XmlWriterSettings()
    settings.Indent = True
    Dim XMLwrt As XmlWriter = XmlWriter.Create("Device.cfg", settings)
    With XMLwrt

        'Write the XML declaration
        .WriteStartDocument()


        'Write the root element
        .WriteStartElement("DEVICES")


        'This will display all elements that user ADD from the button2
        Dim i As Integer = 0
        'For i As Integer = 0 To ioDevice.Length
        Do
            'Start New Device
            .WriteStartElement("DEVICE")


            'Write the attribute element
            .WriteStartAttribute("NAME")
            .WriteString(ioDevice(i).NAME)
            .WriteEndAttribute()


            .WriteStartAttribute("DLL")
            .WriteString(ioDevice(i).Dll)
            .WriteEndAttribute()




            .WriteString(ioDevice(i).ID)


            'The end of Device
            .WriteEndElement()
            i = i + 1


            'the condition where the program should stop looping
        Loop Until (i = ioDevice.Length)


        'Close the XMLTextWritter
        .WriteEndDocument()
        .Close()

    End With
</i>



  <i>Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged

    device.ID = Me.TextBox1.Text
</i>



<i>Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) HandlesTextBox1.TextChanged

    device.NAME = Me.TextBox2.Text
</i>

If your DataSource is a DataSet, you can save to XML directly: 如果您的数据源是数据集,则可以直接保存为XML:

Dim sFilePath As String = "ENTER A VALID FILEPATH"
NorthwindDataSet.WriteXml(sFilePath)

Taken from MSDN: How to: Save a Dataset as XML 取自MSDN: 如何:将数据集另存为XML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM