none
display xml in data grid view RRS feed

  • Question

  • Want to display data in datagridview

    I do not want to use serialize or deserialize, I do not know the xml file. Hope the code work for any xml file

    Wednesday, June 20, 2018 2:56 AM

Answers

  • Hi Mollyyyyyyyy,

    Thank you for posting here.

    You could use dataset. Here is a simple example for your reference.

    My xml file

    <?xml version="1.0" encoding="utf-8" ?> 
    <bookstore>
      <book genre="fantasy"  ISBN="2-3631-4">
        <title>Oberon's Legacy</title>
        <author>Corets, Eva</author>
        <price>5.95</price>
      </book>
    </bookstore>

    My code

    private void button1_Click(object sender, EventArgs e)
            {
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(@"C:\Users\wendyz.WICRESOFT.000\OneDrive\Projects\VS2017 Project\WindowsForms\WindowsForms\Load xml to datagridview.xml");
                dataGridView1.DataSource = dataSet.Tables[0];
            }

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Mollyyyyyyyy Friday, June 22, 2018 11:24 AM
    Friday, June 22, 2018 3:11 AM
    Moderator