Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1104
Grid row filtering with AND and OR
posted

Hi,

I am using a TextBox for quick filtering with the following code:

private void textBoxFilter_TextChanged(object sender, EventArgs e)
        {
            ultraGrid.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
            ultraGrid.DisplayLayout.Bands[0].ColumnFilters.LogicalOperator = FilterLogicalOperator.Or;

            if (textBoxFilter.Text != "")
                foreach (UltraGridColumn col in ultraGrid.DisplayLayout.Rows.Band.Columns)
                {
                    if (col.Hidden)
                        continue;
                    ultraGrid.DisplayLayout.Bands[0].ColumnFilters[col.Key].FilterConditions.Add(FilterComparisionOperator.Contains, textBoxFilter.Text);
                }

}

It filters every visible row with the text of the textbox.

What I am trying to do is to add some RadioButtons to the form, which should set certain filters to a certain column. When these filters are set, the TextBox filters should be applied.

The filter which is set by the RadioButton should be the most important, and the TextBox filters should be applied to this result.

This code doesn't work:

 if (radioButton.Checked)
                ultraGrid.DisplayLayout.Bands[0].ColumnFilters["testcolumn"].FilterConditions.Add(FilterComparisionOperator.Contains, "testtext");

I think it's because of the AND/OR logical operator. When I enter text in the TextBox and the RadioButton is checked, the RadioButton filters should be forced to be applied.

Is there a way to combine these logical operators in some way?

Please tell me if it isn't clear what I want to achieve.

Thank you

Regards

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    The ColumnFilters functionality is limited to either AND or OR. You cannot do both. So there's no way to do what you want here with the built-in filtering alone.

    What you can do is just handle the InitializeRow event of the grid. In this event, you can examine the values of every cell in the row, as well as the radioButton and the TextBox and you can decide whether that row should be shown or not. Then you just set the Hidden property on the row.

    The InitializeRow event is ideally suited to this purpose, since it fires when the row is created and also any time a value in any cell of the row changes. The only thing you would have to do is make sure that the InitializeRow event gets called again when the user changes the radio button or TextBox. You can do this using the Refresh method on the grid's Rows collection.

    grid.Rows.Refresh(FireInitializeRow);

     

    You could also take a hybrid approach and use the ColumnFilters for either the radio button or TextBox filtering and then handle the FilterRow event of the grid to handle the other criteria. But I think the InitializeRow approach would be simpler in this case.

Reply Children
No Data