WPF Datagrid Does Not Display the Result Set

advertisements

I have a list which contains the data that is shown in my WPF Datagrid. I have the following code which searches the grid for a match with a textbox entered string. the code is in a button click handler.

var search = from s in dglist // dglist is my List<APerson>
                         where s.FirstName == textBox1.Text
                         select new
                             {
                                 Firstname = s.FirstName,
                                 Lastname = s.LastName
                             };
dataGrid1.ItemsSource = search;

The last line does not put the resultset in search back into the datagrid, why?


I cannot offer a solution but only a workaround: If you use

dataGrid1.ItemsSource = search.ToList();

the LINQ query will be evaluated right now, which should trigger an update in your list.