Filter out data from an xml file and show it in a datagridview  
Author Message
Surfsune





PostPosted: Visual C# General, Filter out data from an xml file and show it in a datagridview Top

Hi!

Have an xml file that i use like a small database.
To show all the data from the xml file in a datagridview i have done the following code, and it works ok.


private void button5_Click(object sender, EventArgs e)
{
AuthorsDataSet.ReadXml(FILE_NAME);
dataGridView1.DataSource = AuthorsDataSet;
dataGridView1.DataMember = "cd";
}



The xml file looks like this.

< xml version="1.0" encoding="UTF-8" >
<catalog>
<cd id="1">
<name>Sven</name>
<surname>Svensson</surename>
</cd>
</catalog>

I would also like to filter out all posts in the xml file that have name like Sven and show them in a datagridview. Tried to do like the code below but i does not work tha great. When i run it i debug mode i can see that the DataRow array have been populated with the correct data, but the data newer shows up in the datagridview. It only show some column headers that says Rowstate, Table, HasErrors and RowError. Please help a im stuck.



private void button2_Click_1(object sender, EventArgs e)
{

AuthorsDataSet.ReadXml(FILE_NAME);
DataRow[] theFilteredResult = AuthorsDataSet.Tables[0].Select("[namnLIKE'" + this.textBox1.Text + "'");
dataGridView1.DataSource = theFilteredResult;

}


Regards Fredric



Visual C#11  
 
 
ahmedilyas





PostPosted: Visual C# General, Filter out data from an xml file and show it in a datagridview Top

have you tried this

AuthorsDataSet.ReadXml(FILE_NAME);
DataRow[] theFilteredResult = AuthorsDataSet.Tables[0].Select("Name Not LIKE '" + this.textBox1.Text + "'");
dataGridView1.DataSource = theFilteredResult;



 
 
Surfsune





PostPosted: Visual C# General, Filter out data from an xml file and show it in a datagridview Top

I typed little wrong before, it should look like this.

private void button2_Click_1(object sender, EventArgs e)
{

AuthorsDataSet.ReadXml(FILE_NAME);
DataRow[] theFilteredResult = AuthorsDataSet.Tables[0].Select("[name] LIKE '" +
this.textBox1.Text + "'");
dataGridView1.DataSource = theFilteredResult;

}

Yes i tried youre example, i got the same result exept it showed more rows.

The view in the datagrid looks like this.

RowState Table HasError RowError

Added

Added

Added

Added


 
 
Surfsune





PostPosted: Visual C# General, Filter out data from an xml file and show it in a datagridview Top

This i how i made it work.

AuthorsDataSet.Clear();

AuthorsDataSet.ReadXml(FILE_NAME);

DataView dv = new DataView(AuthorsDataSet.Tables[0]);

dv.RowFilter = "name <= '" + Sven + "'";

dataGridView1.DataSource = dv;

/Fredric