471,066 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Datagrid - ReadXml

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.O pen);

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");

}
Nov 17 '05 #1
3 2302
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
Nov 17 '05 #2
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];
}
Nov 17 '05 #3
THANK YOU VERY MUCH :) Cor
it works :)

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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];
}

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Dole | last post: by
2 posts views Thread by Frosty | last post: by
4 posts views Thread by Jussi | last post: by
12 posts views Thread by James Norton-Jones | last post: by
7 posts views Thread by Juan Romero | last post: by
3 posts views Thread by Rodi Roberto | last post: by
3 posts views Thread by Darin | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.