Visual C# Developer Center >
Visual C# Forums
>
Visual C# Language
>
How to write data to dataGridView in c#
How to write data to dataGridView in c#
- Hi, I am reading RSS from a URL and writing it in xml. Uptil here it works fine. Now I want to display the data from xml in a dataGridView. How can I accomplish this. Please help.(This is my first time working with dataGridView. Also how do I bind dataDridView to xml?)
string str = txtUrl.Text; System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument(); XMLDoc.Load("http://address.rss"); XMLDoc.Load(str); NameTable table = new NameTable(); XmlNamespaceManager nsManager = new XmlNamespaceManager(table); nsManager.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); nsManager.AddNamespace("item", "http://purl.org/rss/1.0/"); nsManager.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); System.Xml.XmlNodeList XMLItems = XMLDoc.DocumentElement.SelectNodes("//rdf:RDF/item:item", nsManager); foreach (XmlNode currentItem in XMLItems) { // get the date this.richTextBox2.Text += "Date: " + currentItem.SelectSingleNode("dc:date", nsManager).InnerText + Environment.NewLine; // get the title and the link this.richTextBox2.Text += "Title: " + currentItem.SelectSingleNode("item:title", nsManager).InnerText + " - "; this.richTextBox2.Text += currentItem.SelectSingleNode("item:link", nsManager).InnerText + Environment.NewLine; // get the description this.richTextBox2.Text += "Description: " + currentItem.SelectSingleNode("item:description", nsManager).InnerText + Environment.NewLine + Environment.NewLine; this.Cursor = Cursors.Default; }
Answers
- I have a blog post here:
http://msmvps.com/blogs/deborahk/archive/2009/10/20/populating-a-datagridview-from-xml-data.aspx
That covers how to populate a DataGridView from XML.
Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 2:18 AM
All Replies
- I have a blog post here:
http://msmvps.com/blogs/deborahk/archive/2009/10/20/populating-a-datagridview-from-xml-data.aspx
That covers how to populate a DataGridView from XML.
Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!- Marked As Answer byHarry ZhuMSFT, ModeratorFriday, November 13, 2009 2:18 AM


