To Read XML Data in the DataGridView

21 Sep

This code will allow you to read the data from the XML file and display it in the datagridview.

        DataSet ds = new DataSet();
       private void Form1_Load(object sender, EventArgs e)
        {
            ds.ReadXml(“Data.xml”);
            dataGridView1.DataSource = ds.Tables[0];
        }


To Delete a Row from the DataGridView use the Following Code

    private void button1_Click(object sender, EventArgs e)
        {
            dataGridView1.Rows.RemoveAt(rIndex);
        }
        int rIndex;
       private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            rIndex = e.RowIndex;
        }

The XML File is as Follows

<?xml version=”1.0″ encoding=”utf-8″ ?>

<School>

<student>

<rNumber>1</rNumber>

<SName>Hefin</SName>

<SMarks1>100</SMarks1>

<SMarks2>50</SMarks2>

<SMarks3>70</SMarks3>

</student>

</School>

Regards

Hefin Dsouza.

Share:
  • LinkedIn
  • Twitter

Comments are closed.