This is a migrated thread and some comments may be shown as answers.

Filtering on a boolean value column

2 Answers 266 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jack
Top achievements
Rank 1
Jack asked on 08 Jun 2009, 12:37 AM
I've linked my list of BO's to a treeview and a grid.  As I check off the items in the grid I'm setting an 'IncludeInGrid' bool property to true.  I'm trying then to have the selected rows display in a gridview so I can edit a few columns before going on to the next step. (This is a three step wizard for the users).

Anyhow I'm having a few issues getting the filter to work.  Do you have an example of filtering on a boolean?  Should the FilterOperator be .IsEqualTo  /w with value of "True"?

Thanks

jack

2 Answers, 1 is accepted

Sort by
0
Jack
Top achievements
Rank 1
answered on 08 Jun 2009, 12:58 PM

Just an update - this was a massive over complication of the issue.  All the examples seem to be for creating dynamic filters that change or are UI driven.  I just wanted a basic static filter.  I was able to get this mostly working with fairly simple code:

private class IncludeInDataEntryFilter : FilterDescription  
        {  
 
            public override bool SatisfiesFilter(object dataItem)  
            {  
                DataEntryWizardTask task = dataItem as DataEntryWizardTask;  
 
                if (task != nullreturn task.IncludeInDataEntry;  
                return false;  
            }  
        }
        #endregion  
 
        private readonly IncludeInDataEntryFilter _gridFilter;  
        private DataEntryWizardTask _currentTask;  
 
        public DataEntryWizardView()  
        {  
            // Required to initialize variables  
            InitializeComponent();  
 
            if (_gridFilter == null)  
            {  
                _gridFilter = new IncludeInDataEntryFilter();  
 
                DataEntryWizardTasksGridView.FilterDescription = _gridFilter;  
            }  
        } 

Anyhow now I'm stuck with the filter not updating after I change data in the filtered column.  I now that INotifyPropertyChanged is firing as I can update other column data via CodeBehind and see it reflected... However changing the source data (the filtered column) doesn't cause the grid to show/hide more rows after its initial creation.

I have a  by treeView and my grid on separate tabs.  The first time I open the 2nd tab with my gridView the filtereing works.  However if I go back to the first tab and change data that should cause row filtering changes when I then go back again to the gridView the filtering hasn't been re-applied.  I didn't think I should have to 're-filter' the grid. 

What am I missing?

thanks

jack
0
Rossen Hristov
Telerik team
answered on 09 Jun 2009, 11:08 AM
Hello Jack,

You will need to attach to a suitable event of your treeview or to the PropertyChanged event of your business object (since you mentioned that you are already monitoring it) and reset the FilterDescription. In other words, find the place where you know that the data has changed and simply assign the filter again. This will re-apply the filtering and update the rows as needed.

I have prepared a small sample project that demonstrates this. On the left I have a Microsoft DataGrid that edits the data (like your treeview). I also have a button, which resets the filter when clicked. You will need to move the logic from the button click event handler to a place of your choice. On the right I have a Telerik RadGridView which shows only email messages that are not spam -- my dummy data source is an observable collection of email messages that have a boolean property filtered by a custom filter.

There is another option which is event easier. If you use Telerik's ObservableItemCollection<T>, you can attach to its ItemChanged event and reset the filter there. This will also work.

Please, take a look at the attached sample project and let me know if that is not what you need or if you have trouble implementing it in your real-life application.

Greetings,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Jack
Top achievements
Rank 1
Answers by
Jack
Top achievements
Rank 1
Rossen Hristov
Telerik team
Share this question
or