Search code examples
wpfwpfdatagrid

wpf datagrid.itemsource filter


I have a datagrid in wpf and I used the markup ItemSource="{Binding CompanyTable}" in it. but the problem is, the datagrid loads every single record from the CompanyTable. i'd like to filter it and prevent every entry with a StatusId=0 to show in the datagrid, but how?


Solution

  • use RowFilter and then add rows to a new datatable, may be it looks like :

            DataTable newdt = new DataTable();
            DataRow[] dr = CompanyTable.Select("StatusId = 0");
            foreach (DataRow row in dr)
            {
                newdt.Rows.Add(row);
            }