I've spent some time looking into this, but I cannot seem to find a way to bind a DataGridView (or a DataSet for that matter) to an XmlNode or XmlDocument. I don't have access to the xml file, I get the XML from another method call so DataSet.ReadXml() seems useless for me. It seems like there should be an easy way to do something this simple. Anyone know how to do this
TIA,
DarrelC

Binding DataGridView to XML node or document
Hans Malherbe
XmlNode node;
node = GetNode();
XmlNodeReader nr = new XmlNodeReader(node);
DataSet ds = new DataSet() ;
ds.ReadXml(nr);
this.dataGridView1.DataSource = ds;
nr.Close();
Cheers,
Darrel
randygit
Thorsten Abdinghoff
Cool! I'm kinda surprised that you didn't have to set the DataGridView's DataMember property. Oh well, I learn something everyday!< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
If you think this is a good thing to add to the DataGridView FAQ, please reply to the following post: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=152467&SiteID=1
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
ceswell
The DataGridView only support databinding to a flat structure such as a DataTable in a DataSet. I don't know enough about data tables and < xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />ADO stuff, but you should be able to read XML into a DataTable somehow. I've used DataSet.ReadXml to read in a whole dataset then databind to a specific table in the data set.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
You might ask on theADO forums about reading XML into a datatable: http://forums.microsoft.com/MSDN/ShowForum.aspx ForumID=45&SiteID=1
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Jesse Hersch
For some reason, I am not having any luck in getting this to work.
My questions are:
1. I don't see where the XML file is read into the DataSet.
2. when I try this code into my app, I get the error: "The name 'GetNode' does not exist in the current context". With a bit of looking around, I find that it is a method of IHasXmlNode. But I don't see how to implement this interface to get it to work.
Thanks in advance for any help.
Les