Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DataTable bound to a DataGridView. The DataTable has a boolean column that is a checkbox column in the DataGridView. The user is allowed to filter the DataGridView and when I set DataTable.DefaultView.RowFilter it correctly shows and hides the appropriate rows. What I need to do is uncheck any row that has been hidden. I do a Linq select to get the checked rows and I need to uncheck any rows that are hidden. How do I know if the row is part of the filter or not?

C#
dtBoundDataSource is set and bound to the datagridview above

private void UnselectFilteredRows()
{
    if(dtBoundDataSource != null && dtBoundDataSource.Rows.Count > 0)
    {
        var checkedRows = from cRow in dtBoundDataSource.AsEnumerable()
                          where cRow.Field<bool>(checkedColumnName) == true
                          select cRow;
        
        foreach (var row in checkedRows)
        {
            if(row) //this is where i need to check if the row is visible or hidden
                row.SetField(checkedColumnName, false);
        }
    }
}


Thanks in advance

What I have tried:

I have tried getting a DataView with a NOT filter and that returns no rows. I tried using rowstate, but that is if the row is added, changed, deleted etc. I can not seem to find a setting that shows if it's filtered or not.
Posted

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