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
20
Filtering on Cell with UltraControlContainerEditor
posted

I have a CheckedListBox inside a UltraControlContainerEditor set as the Editor Component of my Cell in my UltraGrid.

Something like this,

UltraGrid > UltraGridCell > UltraGridCell.EditorComponent > UltraControlContainerEditor.EditorControl > CheckedListBox

filter image

I want to apply filtering on the values of the CheckedListBox (Porter,Wendy in this example) which uses a DataSet as DataSource. How can I do that?

Thanks in advance.

Parents
No Data
Reply
  • 69832
    Offline posted

    The UltraControlContainerEditor part of this is basically irrelevant here, since the cell is not aware of the thing providing its value; assuming you have set the UltraControlContainerEditor.EditingControlPropertyName to something that can handle whatever type you're using to represent the checked items, the grid cell will simply get the value from that property. What you need here is a custom filter, which is fairly simple in this case.

    Let's assume your EditingControl handles values of type string[] - each member of the array represents an item that is checked in the CheckedListBox control. The filter can't do a simple Equals comparison since this is not a native type, so you basically have to intervene in that process and decide whether some value is "equal" to the value returned from the EditingControlPropertyName.

    The following code sample demonstrates how to implement a custom filter, which can be added to the FilterConditions collection for the column with the editor component assigned:

    public class MyFilterCondition : FilterCondition
    {
        public MyFilterCondition(string[] searchCriteria)
        {
            this.SearchCriteria = searchCriteria;
        }

        public string[] SearchCriteria
        {
            get;
            private set;
        }

        public override bool MeetsCriteria(UltraGridRow row)
        {
            UltraGridCell cell = row.Cells[0];
            string[] values = cell.Value as string[];

            if ( values == null )
                return false;

            foreach ( string value in values )
            {
                foreach ( string s in this.SearchCriteria )
                {
                    if ( string.Equals(value, s) )
                        return true;
                }
            }

            return false;
        }
    }

    Handle the BeforeRowFilterDropDown event so you can add this filter to the list the user sees when they click the filter icon:

    void grid_BeforeRowFilterDropDown(object sender, BeforeRowFilterDropDownEventArgs e)
    {
        e.ValueList.ValueListItems.Add( new MyFilterCondition(new string[]{"eenie", "meenie", "miley", "moe"}), typeof(MyFilterCondition).Name );
    }

Children
No Data