You can use three ways to filter grid rows. We think that the most convenient way is to implement IFilter interface. In the example below we filter all rows that contain products with price exceeding 10.
C# | Copy |
---|---|
public void HowToSetFilter(Grid grid) { //Set a filter, so the Grid will show products with price greater or equal to 10 grid.Filter = new Filter(delegate(Row row) { //There are three ways to get price: //1. From the Cell through the Value property, which returns a double value: row["Price"].Value //2. Through the IDataAccessor and IDataField: row.DataAccessor["Price"].Value //3. From the data object itself: ((Product)row.DataObject).Price if ((double)row["Price"].Value < 10) { //Filter the row return true; } //The row is not filtered return false; }); //Populate the grid Product product1 = new Product(); Product product2 = new Product(); grid.Rows.Add(product1); grid.Rows.Add(product2); //Update the product's price //Data objects will notify the Grid, and it will display only the product2. //The product1 will be hidden product1.Price = 9; product2.Price = 11; } |
Back to .Net Grid HowTo topics