Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i need to display data in this format to a datagridview. my datasource is XML.
I want to filter the xml file according to the combobox selection.
I have a confusion that whether i am using proper logic for generating data.

please guide me if there is better way to design the xml file.
And one more is it possible to update the xml file from the datagridview
like we do in dataadapter.Update(ds)

<big></big>
        ITEM            X     Y
	amount	          150	210
	amountword	      150	210
	date	          400	250
	payagainst	       30	180



i am using dataset for generating xml
my code is
C#
private void button1_Click(object sender, EventArgs e)
       {
           DataTable dt = new DataTable();
           dt.TableName = "Bank";
           DataColumn dc = new DataColumn("BankName");
           DataColumn dc0 = new DataColumn("item");
           DataColumn dc1 = new DataColumn("X");
           DataColumn dc2 = new DataColumn("Y");
          dt.Columns.Add(dc);
           dt.Columns.Add(dc0);
           dt.Columns.Add(dc1);
           dt.Columns.Add(dc2);
           dt.Rows.Add("xyz","amount", "150", "210");
           dt.Rows.Add("xyz", "amountword", "150", "210");
           dt.Rows.Add("xyz", "date", "400", "250");
           dt.Rows.Add("xyz", "payagainst", "30", "180");

           dt.Rows.Add("abc", "amount", "180", "210");
           dt.Rows.Add("abc", "amountword", "50", "20");
           dt.Rows.Add("abc", "date", "40", "20");
           dt.Rows.Add("abc", "payagainst", "3", "18");
           DataSet ds = new DataSet();
           ds.DataSetName = "chequesettings";
           ds.Tables.Add(dt);
           ds.WriteXml("chequesettings.xml");
           MessageBox.Show("Xml file created sucessfully");
       }

C#
DataSet ds = new DataSet();
           ds.ReadXml("chequesettings.xml");
           dataGridView1.DataSource=ds.Tables[0];


HTML
<chequesettings>
  <Bank>
    <BankName>xyz</BankName>
    <item>amount</item>
    <X>150</X>
    <Y>210</Y>
  </Bank>
  <Bank>
    <BankName>xyz</BankName>
    <item>amountword</item>
    <X>150</X>
    <Y>210</Y>
  </Bank>
  <Bank>
    <BankName>xyz</BankName>
    <item>date</item>
    <X>400</X>
    <Y>250</Y>
  </Bank>
  <Bank>
    <BankName>xyz</BankName>
    <item>payagainst</item>
    <X>30</X>
    <Y>180</Y>
  </Bank>
  <Bank>
    <BankName>abc</BankName>
    <item>amount</item>
    <X>180</X>
    <Y>210</Y>
  </Bank>
  <Bank>
    <BankName>abc</BankName>
    <item>amountword</item>
    <X>50</X>
    <Y>20</Y>
  </Bank>
  <Bank>
    <BankName>abc</BankName>
    <item>date</item>
    <X>40</X>
    <Y>20</Y>
  </Bank>
  <Bank>
    <BankName>abc</BankName>
    <item>payagainst</item>
    <X>3</X>
    <Y>18</Y>
  </Bank>
</chequesettings>
Posted

1 solution

You need to use that filtering operation on your datatable only, what you can do is you can apply filtering by

DataTable.DefaultView.RowFilter= "Your Filter Condition";



for more information you can check below link it also serves your purpose.

http://msdn.microsoft.com/en-us/library/system.data.datatable.defaultview(v=vs.110).aspx[^]



Related to update operation, you can update your grid on basis of that update your datatable as well and accept that changes and now convert your datatable to xml file and replace with existing files.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900