Search code examples
c#wpfdatagridrows

How to return all rows that contain specific value in cell from datatable


I want to return all the rows that contains a specific string to a textbox. I tried a lot of things but didn't get the result i was looking for.

foreach(DataRowView drTesla in dgdArtikel.ItemsSource)
                {
                    if (dgdArtikel.Items.Contains("Tesla"))
                    {
                        // do something
                    }
                }

Description of image, overview datatable and the wanted result

1


Solution

  • Since I am pretty sure your datagrid view has rows of concrete type which you forgot to mention the correct way to do what you need is:

    dgdArtikel.ItemsSource.Cast<Artikel>().Where(i => i.Code == "Tesla")