Mohammad Ghoncheh
Mohammad Ghoncheh

Reputation: 338

Check Value Before Showing In Datagrid

I have a model like this:

   public class product
    {
       public int id;
       public string name;
       public bool show;
    }

Also I have a list with this model:

 List<product> list;

bind:

dataGrid.ItemsSource = list;

Each item of 'list' that have this condition:

if (product.show == false)

shouldn't display in Datagrid.

Please Help Me. Thanks

Upvotes: 0

Views: 39

Answers (2)

david2020
david2020

Reputation: 479

try this:

List<product> sortedList = list.Where(item => item.show != false).ToList();
dataGrid.ItemsSource =sortedList;

Upvotes: 1

Coskun Ozogul
Coskun Ozogul

Reputation: 2469

Try like this :

    dataGrid.ItemsSource = list.Where(ro => ro.show != false).ToList();

Upvotes: 2

Related Questions