Create XML file with C#
-
I developed an application in C # where I have 4 text boxes and a datagrid with 4 columns and multiple rows and a button.
The button should generate an xml file.
I can create the xml file and write the data from text boxes, but not the DataGrid.
Anyone can help me?
At this moment i have this code: In the button action XmlTextWriter writer = new XmlTextWriter("teste.xml", Encoding.GetEncoding("ISO-8859-1")); Writer.Formatting = Formatting.Indented; // for the textboxes: WriteStartElement("textbox1"); WriteElementString(textbox1.text); WriteEndElement(); WriteStartElement("textbox2"); WriteElementString(textbox2.text); WriteEndElement(); WriteStartElement("textbox3"); WriteElementString(textbox3.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); For the datadridview xml output strutured shoud be like this:
<Tabela>
<Tabela-Linha numero="1">
<Id>01</id>
<Nome>Teste1</Nome>
<Cargo>xxx</Cargo>
<Extensao>500</Extensao>
</Tabela-Linha>
<Tabela-Linha numero="2">
<Id>02</id>
<Nome>teste2</Nome>
<Cargo>xxxx</Cargo>
<Extensao>501</Extensao>
</Tabela-Linha>
</Tabela>Can anyone help me?
-
I developed an application in C # where I have 4 text boxes and a datagrid with 4 columns and multiple rows and a button.
The button should generate an xml file.
I can create the xml file and write the data from text boxes, but not the DataGrid.
Anyone can help me?
At this moment i have this code: In the button action XmlTextWriter writer = new XmlTextWriter("teste.xml", Encoding.GetEncoding("ISO-8859-1")); Writer.Formatting = Formatting.Indented; // for the textboxes: WriteStartElement("textbox1"); WriteElementString(textbox1.text); WriteEndElement(); WriteStartElement("textbox2"); WriteElementString(textbox2.text); WriteEndElement(); WriteStartElement("textbox3"); WriteElementString(textbox3.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); For the datadridview xml output strutured shoud be like this:
<Tabela>
<Tabela-Linha numero="1">
<Id>01</id>
<Nome>Teste1</Nome>
<Cargo>xxx</Cargo>
<Extensao>500</Extensao>
</Tabela-Linha>
<Tabela-Linha numero="2">
<Id>02</id>
<Nome>teste2</Nome>
<Cargo>xxxx</Cargo>
<Extensao>501</Extensao>
</Tabela-Linha>
</Tabela>Can anyone help me?
How about foreaching the
[Rows](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx)[[^](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx "New Window")]
collection of the grid, writing the contents of all the[Columns](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns.aspx)[[^](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns.aspx "New Window")]
using the method you already used?object value = dataGridView1.Rows[RowIndex].Cells[ColumnIndex].Value;
Bastard Programmer from Hell :suss:
-
I developed an application in C # where I have 4 text boxes and a datagrid with 4 columns and multiple rows and a button.
The button should generate an xml file.
I can create the xml file and write the data from text boxes, but not the DataGrid.
Anyone can help me?
At this moment i have this code: In the button action XmlTextWriter writer = new XmlTextWriter("teste.xml", Encoding.GetEncoding("ISO-8859-1")); Writer.Formatting = Formatting.Indented; // for the textboxes: WriteStartElement("textbox1"); WriteElementString(textbox1.text); WriteEndElement(); WriteStartElement("textbox2"); WriteElementString(textbox2.text); WriteEndElement(); WriteStartElement("textbox3"); WriteElementString(textbox3.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); For the datadridview xml output strutured shoud be like this:
<Tabela>
<Tabela-Linha numero="1">
<Id>01</id>
<Nome>Teste1</Nome>
<Cargo>xxx</Cargo>
<Extensao>500</Extensao>
</Tabela-Linha>
<Tabela-Linha numero="2">
<Id>02</id>
<Nome>teste2</Nome>
<Cargo>xxxx</Cargo>
<Extensao>501</Extensao>
</Tabela-Linha>
</Tabela>Can anyone help me?
How about using a serializable object as the datasource for the grid then serialize the object?