Finally got it working (below is the code for anyone might be interested in - could appear not ideal, but at least works for me:)):
private void SaveToFile()
{
DataTable dtbl = new DataTable("TestScriptHeader");
dtbl.Columns.Add("TestScriptDescription", typeof(string));
dtbl.Columns.Add("TestScriptPre-Cond", typeof(string));
DataRow dr = dtbl.NewRow();
dr["TestScriptDescription"] = DescriptionText.Text;
dr["TestScriptPre-Cond"] = PreliminaryConditionsText.Text;
dtbl.Rows.Add(dr);
DataSet DS = new DataSet();
DS.Tables.Add(dtbl);
DataTable tsgDataTable = new DataTable("TestScriptGridDataTable");
foreach (DataGridViewColumn column in TestScriptGrid.Columns)
{
if (column.Visible)
{
tsgDataTable.Columns.Add(column.HeaderText);
}
}
object[] cellValues = new object[TestScriptGrid.Columns.Count];
foreach (DataGridViewRow row in TestScriptGrid.Rows)
{
for (int i = 0; i < row.Cells.Count; i++)
{
cellValues[i] = row.Cells[i].Value;
}
tsgDataTable.Rows.Add(cellValues);
}
DS.Tables.Add(tsgDataTable);
DS.WriteXml(@"C:\temp\1111111111.xml", XmlWriteMode.WriteSchema);
}
private void FileOpen_Click(object sender, EventArgs e)
{
if (opnFileDialog.ShowDialog() == DialogResult.OK)
{
fileName = opnFileDialog.FileName;
DataSet DSFromXML = new DataSet();
DSFromXML.ReadXml(fileName, XmlReadMode.ReadSchema);
DataRow dr = DSFromXML.Tables["TestScriptHeader"].Rows[0];
DescriptionText.Text = dr["TestScriptDescription"].ToString();
PreliminaryConditionsText.Text = dr["TestScriptPre-Cond"].ToString();
DataTable DTFromXMLtoGrid = DSFromXML.Tables["TestScriptGridDataTable"];
object[] columnCellValues = new object[DTFromXMLtoGrid.Columns.Count];
TestScriptGrid.Rows.Clear();
foreach (DataRow DRdgv in DTFromXMLtoGrid.Rows)
{
if (DTFromXMLtoGrid.Rows.IndexOf(DRdgv) == DTFromXMLtoGrid.Rows.Count - 1)
break;
for (int c = 0; c < DRdgv.ItemArray.Count(); c++)
{
columnCellValues[c] = DRdgv.ItemArray[c];
}
TestScriptGrid.Rows.Add(columnCellValues);
}
}
}