Visual C# Developer Center > Visual C# Forums > Visual C# Language > How to write data to dataGridView in c#
Ask a questionAsk a question
 

AnswerHow to write data to dataGridView in c#

  • Saturday, November 07, 2009 8:26 PMYo-ho Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    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

All Replies