Hello
How import from xml file to DataGridView? I study 4 days about xml writing and reading and about DataGridView, but cant undestand how?
Please, help me. Maybe show example.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
CrishPosted May 5, 2011, 8:31 AM
create a Xml File and call the Aspx page This Code Help full to use
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml("C:\\books.xml");
DataSet ds = new DataSet("Books DataSet");
ds = xmlDatadoc.DataSet;
dataGridView1.DataSource = ds.DefaultViewManager;
dataGridView1.DataMember = "Book";
Mike JonsonPosted May 18, 2011, 1:53 AM
Sam HobbsPosted May 12, 2011, 4:38 PM
Mike JonsonPosted May 12, 2011, 7:23 AM
Sam HobbsPosted May 12, 2011, 3:48 AM
Mike JonsonPosted May 12, 2011, 2:46 AM
Sam HobbsPosted May 11, 2011, 5:17 PM
DataGridView dgv = new DataGridView();
dgv.Dock = DockStyle.Fill;
f.Controls.Add(dgv);
DataSet ds = new DataSet("Amounts");
ds.ReadXml(filePath);
dgv.DataSource = ds;
dgv.DataMember = "amount";
Application.Run(f);
Mahesh ChandPosted May 11, 2011, 3:41 PM
Mahesh ChandPosted May 11, 2011, 3:40 PM
If it is a new form (window), then on first Form, you need to call fDebit.Show() and then write your XML load code on the fDebit's Form Load.
Also change,
this.dataGridView_Debit.DataSource = ds.Tables[0];
Sam HobbsPosted May 11, 2011, 1:04 PM
Your code has "fDebit db=new fDebit();" in it. I don't know what that is supposed to do but I doubt that it does what you intend it to. So the DataGridView that you are using (db.dataGridView_Debit) is not the one you see in the form.
Finally, you are not setting the DataMember property of the DataGridView. Set it to the table name ("amount"). If you look at the articles and samples again, I am sure you will see that you need to do that also.
Mike JonsonPosted May 11, 2011, 9:03 AM
-
-
-
And i use this code:
private void Form1_Load(object sender, EventArgs e)
{
//if file not found
if (!File.Exists(filePath))
{
//create new file
createXMLDocument(filePath);
}
else
{
//import from xml file to DataGridView
DataSet ds = new DataSet("Amounts");
ds.ReadXml(filePath);
fDebit db=new fDebit();
db.dataGridView_Debit.DataSource = ds;
But .dataGridView is clear. Whe is problem, please help me.
Mike JonsonPosted May 11, 2011, 1:44 AM
Mahesh ChandPosted May 10, 2011, 10:40 AM
http://msdn.microsoft.com/en-us/library/system.data.dataset_properties.aspx
Mike JonsonPosted May 10, 2011, 8:19 AM
Sam HobbsPosted May 5, 2011, 11:46 PM
Mahesh ChandPosted May 5, 2011, 7:46 AM
Something like this:
string yourXmlFileWithFullPath = @"C:\PutFullPath\XmlFileName.xml";