[英]datagridview to xml file vb.net
我真的需要您的帮助。
我已经完成了从文本框+按钮编写代码的操作,以创建并写入xml文件。 因此,现在我尝试应用相同的详细信息,但使用datagridview(无文本框)。
我仍然很新,我真的不知道如何应用单元格,索引以及有关datagridview的所有信息。
例如,我在TEXTBOX 1中作为ID的详细信息,在TEXTBOX 2中作为NAME的详细信息,因此我将ID作为ID转移到DATAGRIDVIEW列(0),作为NAME转移至column(1),因此每当用户在ID和NAME的每行中键入ID / NAME时,单击按钮将其转换为XML文件
所以我真的需要您的帮助,如何在我的代码中应用这些东西:
<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>
如果您的数据源是数据集,则可以直接保存为XML:
Dim sFilePath As String = "ENTER A VALID FILEPATH"
NorthwindDataSet.WriteXml(sFilePath)
取自MSDN: 如何:将数据集另存为XML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.