Bradley George

Bradley George

  • NA
  • 13
  • 39.7k

Help with creating a filter for a data grid!

Dec 8 2010 4:39 PM
I want to create a filter to filter text in a datagrid as i type in a text box. I have two text boxes, one to filter in text that i type and one to filter out text that i type. I want the data grid to update as i type into either one of the textboxes. Here is some of my code:


private void txtFilterIn_TextChanged(object sender, TextChangedEventArgs e)
        {
            DataView dv = dgPortStatus.DataContext as DataView;
            if (dv != null)
            {
                if (dv.Table.TableName.ToUpper() == "PORTSTATUS")
                {
                    FilterDataGrid(txtFilterIn.Text, txtFilterOut.Text, _dicPortStatus[cmbGroups.SelectedItem.ToString()]);
                }
            }

            List<QuarantineView> qvList = dgPortStatus.DataContext as List<QuarantineView>;
            if (qvList != null)
            {
                //Filter on quarantine manager
                FilterQuarantineViewList(qvList);
            }
        }

        private void btnFilterInClear_Click(object sender, RoutedEventArgs e)
        {
            txtFilterIn.Clear();
        }

        private void txtFilterOut_TextChanged(object sender, TextChangedEventArgs e)
        {
            DataView dv = dgPortStatus.DataContext as DataView;
            if (dv != null)
            {
                if (dv.Table.TableName.ToUpper() == "PORTSTATUS")
                {
                    FilterDataGrid(txtFilterIn.Text, txtFilterOut.Text, _dicPortStatus[cmbGroups.SelectedItem.ToString()]);
                }
            }

            List<QuarantineView> qvList = dgPortStatus.DataContext as List<QuarantineView>;
            if (qvList != null)
            {
                //Filter on Quarantine Manager
                FilterQuarantineViewList(qvList);
            }
        }

        private void btnFilterOutClear_Click(object sender, RoutedEventArgs e)
        {
            txtFilterOut.Clear();
        }

And this method is where my filter needs to go:

private void FilterQuarantineViewList(List<QuarantineView> qvList)
{
           
        
}

Answers (5)