Click here to Skip to main content
15,887,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datagridView and I'm trying to filter some row using Id row , it work fine but the problem is when for example I check the datagridCheckboxColumn and I click in the searchbox ( TextChanged event ) , I lost the items checked

How can I recover the checked items when I'm using the searchbox?

What I have tried:

C#
private void Idtxt_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (Idtxt.Text.ToString().Equals(""))
            {
                DataGrid.ItemsSource = dataModelList; 

            }
           List<DataGridModel> filtered = dataModelList.Where(DataGridModel => DataGridModel.workId.StartsWith(Idtxt.Text)).ToList();
        
            DataGrid.ItemsSource = filtered;
Posted
Updated 14-Sep-20 4:46am
v2

1 solution

By setting ".ItemSource" you're rebinding the Grid (and "losing" what was there). You need a "view" that doesn't alter the item source once you've "checked" (since it's not evident that you're actually propagating changes).

How to: Group, sort, and filter Data in the DataGrid control - WPF .NET Framework | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900