Row Filtering in dataset

  • Thread starter Thread starter DBC User
  • Start date Start date
D

DBC User

I have a data set which has a data table. This dataset is set as a
datasource for a display grid. Before I assign the data set to data
grid, I would like to elliminate some rows from the data table. How can
I do this?

I saw an example where I can identify the table and then apply the
select on the table. Which returns the data rows. Is there a way I can
remove the rows without doing this 2 step process of obtaining the data
row and then put the data row back in the table etc.,??

Thanks.
 
The original input is XML that I convert to DataSource. Any
suggestions?
Thanks.
 
Hi,

You can bind the grid to a DataView:

DataView view = new DataView(myDataTable);

// the following code does not modify the underlying DataTable
// it only provides a logical "view" of the data to which you can bind the grid
view.RowFilter = "Column1 = 'a value.'";

// Although we're assigning the DataView as the source and not the DataTable,
// you can still configure the grid in exactly the same way as you would for your DataTable.
// i.e. You can use the same column names for binding.
// (Internally, most framework controls switch to a DataView anyway when binding to a DataTable, AFAIK.)
grid.DataSource = view;

The following link describes the expression syntax that you can use for the RowFilter property and other DataSet expressions:

DataColumn.Expression property on MSDN:
http://msdn2.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
 
DBC,

There is nothing wrong with looping through the table and to remove the
datarows you do not want
If it is not a database related table, than it is not important if you use
delete or remove.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top