private void MakeParentGroupsInvisibleIfNoRowsVisible(Group group)
        {
            bool atLestOneRowVisible = false;

            ReadOnlyDataRowList groupDataRows = group.GetSortedDataRows(true);
            int groupDataRowsCount            = groupDataRows.Count;

            for (int i = 0; i < groupDataRowsCount; i++)
            {
                DataRow groupDataRow = groupDataRows[i];

                if (groupDataRow.Visible == true)
                {
                    atLestOneRowVisible = true;
                    break;
                }
            }

            if (!atLestOneRowVisible)
            {
                group.Visible = false;

                Group parentGroup = group.ParentGroup as Group;

                if (parentGroup != null)
                {
                    this.MakeParentGroupsInvisibleIfNoRowsVisible(parentGroup);
                }
            }
        }
        private void InitFilterLists()
        {
            try
            {
                // Only build the list from the values under the FilterRow's hierarchical position.
                GroupBase           groupBase = this.ParentGroup;
                ReadOnlyDataRowList dataRows  = groupBase.GetSortedDataRows(true);

                //int dataRowsCount = dataRows.Count;
                DetailGrid parentGrid = groupBase as DetailGrid;

                if (parentGrid == null)
                {
                    parentGrid = groupBase.ParentGrid;
                }

                int cellsCount = parentGrid.Columns.Count;

                // Clear the existing lists.
                for (int i = 0; i < cellsCount; i++)
                {
                    FilterCell filterCell = (FilterCell)this.Cells[i];
                    if (filterCell.Visible)
                    {
                        filterCell.FillFilterList();
                    }
                }

                //for (int i = 0; i < dataRowsCount; i++)
                //{
                //    DataRow dataRow = dataRows[i];

                //    for (int j = 0; j < cellsCount; j++)
                //    {
                //        FilterCell filterCell = (FilterCell)this.Cells[j];

                //        // If the cell is Visible, add its value to the list.
                //        if (filterCell.Visible)
                //            filterCell.AddToFilterList(dataRow.Cells[j]);
                //    }
                //}
            }
            catch (Exception ex)
            {
                throw new GridException("An error occured while filling the FilterRow's filter list.", ex);
            }
        }
        /// <summary>
        ///
        /// </summary>
        public void FillFilterList()
        {
            if (!this.Visible)
            {
                return;
            }

            FilterRow filterRow = this.ParentRow as FilterRow;

            // Only build the list from the values under the FilterRow's hierarchical position.
            GroupBase           groupBase = filterRow.ParentGroup;
            ReadOnlyDataRowList dataRows  = groupBase.GetSortedDataRows(true);

            int        dataRowsCount = dataRows.Count;
            DetailGrid parentGrid    = groupBase as DetailGrid;

            if (parentGrid == null)
            {
                parentGrid = groupBase.ParentGrid;
            }

            //int cellsCount = parentGrid.Columns.Count;

            //object savedValue = this.Value;

            IFilter customFilter = m_filterItems.ContainsKey(s_customText) ? m_filterItems[s_customText] : null;

            // Clear the existing lists.
            this.ClearFilterList();
            for (int i = 0; i < dataRowsCount; i++)
            {
                Xceed.Grid.DataRow dataRow = dataRows[i];
                this.AddToFilterList(dataRow.Cells[this.FieldName]);
            }

            // Add Any and custom
            m_filterItems[s_anyText]    = new AnyFilter();
            m_filterItems[s_customText] = customFilter;

            // Fill editor and viewer
            this.FillViewerAndEditor();

            //this.Value = savedValue;
        }
        /// <summary>
        ///
        /// </summary>
        public void UnApplyFilters()
        {
            // Set all groups/dataRows to be visible.
            GroupBase parentGroup = this.ParentGroup;

            if (parentGroup == null)
            {
                return;
            }

            ReadOnlyDataRowList siblingDataRows = parentGroup.GetSortedDataRows(true);
            int siblingDataRowsCount            = siblingDataRows.Count;

            for (int i = 0; i < siblingDataRowsCount; i++)
            {
                siblingDataRows[i].Visible = true;
            }

            this.ShowAllGroups(this.GridControl.Groups);

            RaiseFilteredEvent();
        }
        /// <summary>
        ///
        /// </summary>
        public void ApplyFilters()
        {
            if (!this.Enabled)
            {
                return;
            }

            GroupBase parentGroup = this.ParentGroup;

            if (parentGroup == null)
            {
                return;
            }

            ReadOnlyDataRowList siblingDataRows = parentGroup.GetSortedDataRows(true);
            int siblingDataRowsCount            = siblingDataRows.Count;

            int cellsCount = this.Cells.Count;

            for (int i = 0; i < siblingDataRowsCount; i++)
            {
                DataRow dataRow = siblingDataRows[i];

                bool rowMatchesFilter = true;

                for (int j = 0; j < cellsCount; j++)
                {
                    if (!this.Cells[j].Visible)
                    {
                        continue;
                    }

                    FilterCell filterCell = (FilterCell)this.Cells[j];

                    IFilter filter = filterCell.GetFilter();

                    //object cellValue = dataRow.Cells[j].Value;
                    if (filter != null)
                    {
                        rowMatchesFilter = filter.Evaluate(dataRow.Cells[j].CellViewerManager is INameValueControl ? dataRow.Cells[j].GetDisplayText() :
                                                           dataRow.Cells[j].Value);
                    }

                    if (!rowMatchesFilter)
                    {
                        break;
                    }
                }

                dataRow.Visible = rowMatchesFilter;

                // If the row belongs to a group, set the group visibility accordingly to its rows visibility.
                // The group will be hidden if all of its dataRows are filtered out.
                // If at least one dataRow is visible, then the group should also be visible.
                Group dataRowParentGroup = dataRow.ParentGroup as Group;

                if (dataRowParentGroup != null)
                {
                    if (rowMatchesFilter)
                    {
                        MakeParentGroupsVisible(dataRowParentGroup);
                    }
                    else
                    {
                        MakeParentGroupsInvisibleIfNoRowsVisible(dataRowParentGroup);
                    }
                }
            }

            RaiseFilteredEvent();
        }