views:

438

answers:

2

Hi all,

I want to find cells in column strSearchFilter that DO contain a value (any value) and hide the rows that DO NOT have a value (i.e. NULL). My code below returns all rows that have NULL in the strSearchFilter column the opposite to what I want.

Thanks

    strSearchFilter += string.IsNullOrEmpty(txtFilterValue.Text) ? " IS NULL" : " NOT LIKE '%" + txtFilterValue.Text + "%'"; 
    }

private void performFilter(string strFilterText)
{
        DataTable table = dataGridView1.DataSource as DataTable;
        if (table != null)
        {
            List<DataRow> filteredRows = new List<DataRow>(table.Select(strFilterText));

            CurrencyManager cm = (CurrencyManager)BindingContext[dataGridView1.DataSource];
            cm.SuspendBinding();
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.Visible = filteredRows.Contains(((DataRowView)row.DataBoundItem).Row);
            }
            cm.ResumeBinding();
        }
}

Thanks for the help.

A: 

You need to write the following:

strSearchFilter += string.IsNullOrEmpty(txtFilterValue.Text) ? " IS NOT NULL" : " NOT LIKE '%" + txtFilterValue.Text + "%'";
SLaks
+1  A: 

I suggest using the column you want your filter to apply to and use simple SQL syntax such as:

MyColumn IS NOT NULL AND MyColumn <> ''

Is that what you're looking for?

Maxime