Information générale
Titre:
DataGrid Basics tying to XML
I've looked and read, but appear to just not getting it.
I'm using C# in .Net 2003 compact framework.
The client calls a web service setup to a VFP8 dll that returns an XML file with the schema included. That portion works like expected. The XML file is then read and bound to a datagrid. The data displays but for the life of me I can't get the columns to display the data I want, the data being displayed is correct, just not the correct headings and column order.
I'm not using TablesStyles from the UI but coding them instead, tried the other way and same problem.
Here's the code below. Any comments would be welcome.
Thanks
Jon
note: lu.ItemXML XML returned from webservice
this.ds = new DataSet();
string xml = lu.ItemXML;
this.ds.ReadXml(new XmlTextReader(new StringReader(xml)), System.Data.XmlReadMode.ReadSchema);
if (this.ds.Tables.Count != 0)
{
// Bind the data to the object
this.dgItemListing.DataSource = ds.Tables[0].DefaultView;
// Clear previous TableStyles
this.dgItemListing.TableStyles.Clear();
// Columns in dgItemListing
// Create an instance of the DataGridTableStyle class
// Set its MappingName property to the name of the table
DataGridTableStyle ts1 = new DataGridTableStyle();
// Next create an instance of DataGridColumnStyle for each column
DataGridColumnStyle textCol1 = new DataGridTextBoxColumn();
textCol1.MappingName = "cItemID";
textCol1.HeaderText = "Item ID";
textCol1.Width = 150;
ts1.GridColumnStyles.Add(textCol1);
DataGridColumnStyle textCol2 = new DataGridTextBoxColumn();
textCol2.MappingName = "cDescrip";
textCol2.HeaderText = "Description";
textCol2.Width = 250;
ts1.GridColumnStyles.Add(textCol2);
// Last add the Table styles to the DataGrid
this.dgItemListing.TableStyles.Add(ts1);
}
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement