Hi!
I am new to C#. Now I have one project which needs to read a 130kb xml file, and display some of its data with a GUI.
What component I should use to display the data? I need a combobox to select between different datasets.
Anyone can help. Thanks a lot.....Thanks
BR
Emma
Loading

Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 21, 2013, 11:17 PM EDT
I thing, you can use datagrid view control show the selected table data.
DataSet ds = new DataSet();
ds.ReadXml(@"E:\test\testProject\testProject\testProject\XMLFile1.xml");
are you using window base application or web base application?
both type of application containing datagrid.
hope this will help you.
Emma Emma80 reputationPosted Apr 23, 2013, 12:30 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 23, 2013, 1:53 AM EDT
hi,
there is good idea to create other datasource and assign it to data grid view.
DataSet ds = new DataSet();
ds.ReadXml(@"E:\test\testProject\testProject\testProject\XMLFile1.xml");
//here you may specify the page numbers instead of 200.
var newdt = ds.Tables[0].AsEnumerable().Skip(200).Take(200).CopyToDataTable();
datagrid1.DataSource = newdt;
hope this will help you.
Emma Emma80 reputationPosted Apr 23, 2013, 2:04 AM EDT
Thanks again.
But the problem is that my .xml file may change, my program should work for different files not only one. So I can not count how many to take or to skip.
The only thing I have is that the ID is different.. some is 100 -200 some is 400,500...
so I need to split them ...:(
Hope you understand what I mean
BR
Emma
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 23, 2013, 2:31 AM EDT
ok ideally you want to show first 200 and on next button click want to show next 200.
right?
to achieve this you have to introduced you own logic.
I have try with following code it work. it might also work for you
try
// page index is change from your next or previous button
int pageIndex = 0;
int pageRecord = 200;
DataTable newdt;
var dymmydataTable = ds.Tables[0];
//if record is in between current
if ((pageIndex + 1) * pageRecord > dymmydataTable.Rows.Count)
{
newdt = dymmydataTable.AsEnumerable().Skip(pageIndex * pageRecord).CopyToDataTable();
}
else
{
newdt = dymmydataTable.AsEnumerable().Skip(pageIndex * pageRecord).Take((pageIndex + 1) * pageRecord).CopyToDataTable();
}
hope this will help you.
Emma Emma80 reputationPosted Apr 23, 2013, 3:21 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 23, 2013, 3:44 AM EDT
hi,
from this above code you might got the idea how to accomplish the task.
I am sure that above code can help you to build your own logic.
Emma Emma80 reputationPosted Apr 23, 2013, 3:51 AM EDT
Yes. I am trying to do it with the code you gave...but ..I never use C# before, this gives little challenge to me... But lets see. Maybe I will make it !Thanks so much.
BR Emma
Emma Emma80 reputationPosted Apr 23, 2013, 4:17 AM EDT
Hi,
I think your idea is doable for my project. Can you tell me
is newdt is a data table?
After this :dataGridView1.DataSource = newdt; I should copy the data from table to dataset. Is that so? And How to do this.. I get confused ...
Thanks !
BR
Emma
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 23, 2013, 5:04 AM EDT
Answer is as below
1) Yes
2) no , you do nothing after this.
in above piece of code we already assign new data in to newdt data table.
hope this will help you.
Emma Emma80 reputationPosted Apr 23, 2013, 10:19 PM EDT
Ravikumar G178 reputationPosted Apr 23, 2013, 10:43 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 23, 2013, 11:52 PM EDT
It only shows the first line of xml file, I think reason behind we are taking first table of dataset.
var dymmydataTable = ds.Tables[0];
it might be possible, other datatable of the dataset has value that you required.
also please share sample of your xml file.
Emma Emma80 reputationPosted Apr 24, 2013, 12:41 AM EDT
Emma Emma80 reputationPosted Apr 24, 2013, 12:52 AM EDT
Ravikumar G178 reputationPosted Apr 24, 2013, 12:52 AM EDT
Ravikumar G178 reputationPosted Apr 24, 2013, 1:21 AM EDT
Emma Emma80 reputationPosted Apr 24, 2013, 1:35 AM EDT
Emma Emma80 reputationPosted Apr 24, 2013, 1:37 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 24, 2013, 7:25 PM EDT
hi,
Please refer following link it might help you.
http://support.microsoft.com/kb/308333
http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C
http://shahvaibhav.com/how-to-read-xml-attributes-using-xpath-in-c/
Shankar MRank #874 · 2.5K reputationPosted Apr 24, 2013, 8:29 PM EDT
Hope this link might help you.
http://www.c-sharpcorner.com/UploadFile/c5c6e2/binding-xml-data-to-listview-control-dataset-approach/
Emma Emma80 reputationPosted Apr 25, 2013, 10:01 PM EDT
Shankar MRank #874 · 2.5K reputationPosted Apr 25, 2013, 11:19 PM EDT
Can you Please try checking this,
http://csharp.net-informations.com/xml/xml-to-datagridview.htm
Emma Emma80 reputationPosted Apr 26, 2013, 12:48 AM EDT
Emma Emma80 reputationPosted Apr 26, 2013, 2:11 AM EDT
Here is my result. I can make it in ListBox. But the first three should be in one row. not column.
That is why I want it in DataGridView.
Can anyone help me with this: only select part of the nodes, and every node only display three items...
Thanks
//// three items from one node
100
A10
Low Filter