Hi all,
Hopefully someone will come to my rescue!!
I've used the code below to get the data from an xml file, this works fine.
Problem is, I can't fathom out how to programatically do anything with the data.
The form has:
DataGridView named PhotoGrid
Button named btnReadXML
Button named btnShowSchema
Both the read and write (btnShowSchema) buttons does as it should.
I as a sample, I would like to be able to loop through each record and return each cell's value within the record.
with Access I'd do something like For Each Rec in Record
One point to note the DataGrid is dark grey to start with then on pressing the read, the column headers appear from the XML file - can I not define the headers first then get the data inported to them? Have I done something wrong?!
Thanks everyone.
Aubs
Hopefully someone will come to my rescue!!
I've used the code below to get the data from an xml file, this works fine.
Problem is, I can't fathom out how to programatically do anything with the data.
The form has:
DataGridView named PhotoGrid
Button named btnReadXML
Button named btnShowSchema
Both the read and write (btnShowSchema) buttons does as it should.
I as a sample, I would like to be able to loop through each record and return each cell's value within the record.
with Access I'd do something like For Each Rec in Record
One point to note the DataGrid is dark grey to start with then on pressing the read, the column headers appear from the XML file - can I not define the headers first then get the data inported to them? Have I done something wrong?!
Thanks everyone.
Aubs
Code:
[blue]using[/blue] System;
[blue]using[/blue] System.Collections.Generic;
[blue]using[/blue] System.ComponentModel;
[blue]using[/blue] System.Data;
[blue]using[/blue] System.Drawing;
[blue]using[/blue] System.Text;
[blue]using[/blue] System.Windows.Forms;
[blue]namespace[/blue] PrintingSample03
{
[blue]public partial class[/blue] [teal]Form1[/teal] : [teal]Form[/teal]
{
[teal]DataSet[/teal] dsPhotos = [blue]new[/blue] [teal]DataSet[/teal]([COLOR=brown]"PhotoList"[/color]);
[blue]public[/blue] Form1()
{
InitializeComponent();
}
[blue]private void[/blue] btnReadXML_Click([blue]object[/blue] sender, [teal]EventArgs[/teal] e)
{
dsPhotos.Clear();
[blue]string[/blue] filePath = [COLOR=brown]"C:\\Projects\\Sample\\sample.xml"[/color];
dsPhotos.ReadXml(filePath);
PhotoGrid.DataSource = dsPhotos;
PhotoGrid.DataMember = [COLOR=brown]"PHOTO"[/color];
}
[blue]private void[/blue] btnShowSchema_Click([blue]object[/blue] sender, [teal]EventArgs[/teal] e)
{
WriteXmlToFile(dsPhotos);
[teal]MessageBox[/teal].Show([COLOR=brown]"Details saved to file"[/color]);
}
[blue]private void[/blue] WriteXmlToFile([teal]DataSet[/teal] thisDataSet)
{
[blue]if[/blue] (thisDataSet == [blue]null[/blue]) { [blue]return[/blue]; }
[green]// Create a file name to write to.[/green]
string filename = [COLOR=brown]"C:\\Projects\\Sample\\sample.xml"[/color];
[green]// Create the FileStream to write with.[/green]
System.IO.FileStream myFileStream = new System.IO.FileStream
(filename, System.IO.FileMode.Create);
[green]// Write to the file with the WriteXml method.[/green]
thisDataSet.WriteXml(myFileStream);
}
[blue]private void[/blue] button1_Click([blue]object[/blue] sender, [teal]EventArgs[/teal] e)
{
[green]//Something to go here to loop through[/green]
}
}
}