Datagrid - ReadXml

R

Raj Chudasama

I am trying to read an xml file and have it view data in the datagrid. (For
example take the xml file viewer in the visual studio, when u open an xml
file it has that nice readable grid).

I though that when i use the ReadXml funtion it will automatically read data
and add the data to the datagrid.

but i am wrong its not that simple. so i need help only with adding the data
to the datagrid.
this is what i have so far. I have created the grid with coulum names now i
need to add the rows of data. please help me :) thanks
private void CreateDataSet(string fileName)

{

DataSet newDataSet = new DataSet("New Data Set");

System.IO.FileStream readXml = new
System.IO.FileStream(fileName,System.IO.FileMode.Open);

newDataSet.ReadXml(readXml);

readXml.Close();

DataTable myTable = new DataTable("Mytable");

DataColumn cl1 = new DataColumn("Date");

DataColumn cl2 = new DataColumn("Device");

DataColumn cl3 = new DataColumn("call id");

DataColumn cl4 = new DataColumn("source");

DataColumn cl5 = new DataColumn("destination");

myTable.Columns.Add(cl1);

myTable.Columns.Add(cl2);

myTable.Columns.Add(cl3);

myTable.Columns.Add(cl4);

myTable.Columns.Add(cl5);


////////////// ADD ROWS HERE??????????////////

newDataSet.Tables.Add(myTable);


dataGrid1.SetDataBinding(newDataSet,"Mytable");

}
 
C

Cor Ligthert [MVP]

Raj,

This does probably what you want.
private void CreateDataSet(string fileName)
{
DataSet newDataSet = new DataSet();
newDataSet.ReadXml("FullPath");
dataGrid1.DataSource = newDataSet.Tables[0];
}

I hope this helps,

Cor
 
C

Cor Ligthert [MVP]

Oeps, I did not see you where passing the path


private void CreateDataSet(string fileName)
{
DataSet newDataSet = new DataSet();
newDataSet.ReadXml(fileName);
dataGrid1.DataSource = newDataSet.Tables[0];
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top