Hi - I have a form with a DataGridView and I want to load data from an XML file into the Grid using a DataSet. I create a DataSet, load the XML into the DataSet, then assign the DataSet to the DataSource property of the Grid:
private void formAccountHistory_Load(object sender, EventArgs e)
{
// Load the DataSet that represents the offline version of the database.
AccountHistoryDS = new DataSet("TicketAccountHistory");
AccountHistoryDS.ReadXmlSchema("TicketsAccountHistory.xsd");
AccountHistoryDS.ReadXml("TicketsAccountHistory.xml", XmlReadMode.Auto);
AccountHistoryDS.Locale = System.Globalization.CultureInfo.CurrentUICulture;
dataGridViewStatement.AutoGenerateColumns = false;
dataGridViewStatement.DataSource = AccountHistoryDS;
dataGridViewStatement.DataMember = "Line";
}
However the data doesn't display in the Grid. I have 8 rows in the XML file and the Grid creates 8 rows alright but they are all blank. When I debug the code I can see the data in the DataSet so it seems to be loading it correctly to that point, just not displaying it in in the Grid. The XML file I use is below - it is well formed and validates against its schema:
<?xml version="1.0" standalone="yes"?>
<TicketsAccountHistory>
<Line>
<colID>03/09</colID>
<colStartEnd>14/01/2009-20/01/2009</colStartEnd>
<colDate>14/01/2009</colDate>
<colType>Period 03/09 - opening balance</colType>
<colDR></colDR>
<colCR></colCR>
<colBalance>0.00</colBalance>
</Line>
<Line>
<colID>03/09</colID>
<colStartEnd>14/01/2009-20/01/2009</colStartEnd>
<colDate>20/01/2009</colDate>
<colType>Sales Invoice (Ref: MRO-S-03/09)</colType>
<colDR>1000</colDR>
<colCR></colCR>
<colBalance>1000.00</colBalance>
</Line>
<Line>
<colID>03/09</colID>
<colStartEnd>14/01/2009-20/01/2009</colStartEnd>
<colDate>20/01/2009</colDate>
<colType>Commission Invoice (Ref: MRO-C-03/09)</colType>
<colDR></colDR>
<colCR>100.00</colCR>
<colBalance>900.00</colBalance>
</Line>
<!-- 5 more rows similar to this -->
</TicketsAccountHistory>
Can anyone tell me what I might be doing wrong? I'm new to .NET 3.5 and the DataGridView and I don't know how what events are fired when a Grid is populated, if there should be code in any of those events, etc. Any help appreciated.
Cheers, Ciaran.