I have a DataGridView whose DataSource is a DataView based off of a Datable.
I am allowing the user to filter the DataGridView based on value in cells within a Column.
After the user selects the value to filter - I create a filter string and apply it to the Datatable and then create a DataView based on the DataTable's filtered records set. Then, the DataGridView Datasource is now the new DataView.

All works well at this point.
However, as soon as the user edits a cell in the column that was filtered, and that value is different than the value sent as part of the filter string - the DataGridView then gets refiltered immediately - almosts like deleting a row.

Is there a way to make this behavior similar to Excel where you can lets say filter a column for "blanks" - and then even if the user edits the cells that are blank, that original filtered dataset remains until the user unfilters?

Hi...so I have not seen a response to this...was my description to vague? Or, is this not solvable?

So I came up with this. I am hoping maybe someone has a better idea.

'DTInput is my DataTable which supplies the Final DataView for the DataGridView datasource

        ' Get Filterstring or concatenated FilterString
         If Not String.IsNullOrEmpty(FilterString) Then
            FilterString = FilterString & " AND [" & sCurrentColumn & "] = '" & sFilterValue & "' "
         Else
            FilterString = "[" & sCurrentColumn & "] = '" & sFilterValue & "' "
         End If

        'Support for Editing while DataGridView is in filter mode
        'Column 24 is used for Filtering and is hidden
        'This uses the first Filterstring above to mark rows for filtering
        'The default value in Column 24 is "0"
        'So, multiple filters can end up like this: "01111"
        result = DTInput.Select(FilterString)
        For Each DataRow In result
            DataRow.Item(24) = DataRow.Item(24) & "1"
        Next

       'This becomes the new FilterString for the Final DataGridView Datasource
        'sDTFilter default value is "0". Similar to the column 24 above
        sDTFilter = sDTFilter & "1"

        FilterString2 = "[Filter] = '" & sDTFilter & "'"
        DVInput = New DataView(DTInput, FilterString, "Project Definition", DataViewRowState.CurrentRows)
        dgv.DataSource = DVInput

        'So now, by editing any column in the "Filtered" DataGridview, the DataGridview is
        'not immediately refiltered based on the different value entered in any cell because I am using the Hidden Column 24
        ‘for filtering. I don’t like having to loop thru the rows to mark records for filtering first, but I can’t think of any other
        ‘way right at this time. 

Sorry, there was a typo in the last filter.

'was this
DVInput = New DataView(DTInput, FilterString, "Project Definition", DataViewRowState.CurrentRows)
'should be this
DVInput = New DataView(DTInput, FilterString2, "Project Definition", DataViewRowState.CurrentRows)

Edited 3 Years Ago by midnite11: mistake

This article has been dead for over six months. Start a new discussion instead.