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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
CrishRank #1,486 · 1.1K reputationPosted May 5, 2011, 4:31 AM EDT
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";
Mahesh ChandRank #1 · 393.3K reputationPosted May 5, 2011, 3:46 AM EDT
Something like this:
string yourXmlFileWithFullPath = @"C:\PutFullPath\XmlFileName.xml";
Sam HobbsRank #107 · 20.5K reputationPosted May 5, 2011, 7:46 PM EDT
Mike JonsonRank #7,584 · 238 reputationPosted May 10, 2011, 4:19 AM EDT
Mahesh ChandRank #1 · 393.3K reputationPosted May 10, 2011, 6:40 AM EDT
http://msdn.microsoft.com/en-us/library/system.data.dataset_properties.aspx
Mike JonsonRank #7,584 · 238 reputationPosted May 10, 2011, 9:44 PM EDT
Mike JonsonRank #7,584 · 238 reputationPosted May 11, 2011, 5:03 AM EDT
-
-
-
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.
Sam HobbsRank #107 · 20.5K reputationPosted May 11, 2011, 9:04 AM EDT
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.
Mahesh ChandRank #1 · 393.3K reputationPosted May 11, 2011, 11:40 AM EDT
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];
Mahesh ChandRank #1 · 393.3K reputationPosted May 11, 2011, 11:41 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 11, 2011, 1:17 PM EDT
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);
Mike JonsonRank #7,584 · 238 reputationPosted May 11, 2011, 10:46 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 11, 2011, 11:48 PM EDT
Mike JonsonRank #7,584 · 238 reputationPosted May 12, 2011, 3:23 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted May 12, 2011, 12:38 PM EDT
Mike JonsonRank #7,584 · 238 reputationPosted May 17, 2011, 9:53 PM EDT