I have the following situation:
A grid contains a list of projects with a column called "Status'. Status can be either Active or Inactive. When we populate both Active and Inactive projects into grid, default filter on Status column will have check boxes for both Active and Inactive.
Now to improve performance, I don't want to populate all projects initially but only Active. Now that we have populated only active projects, filter on Status column will have a checkbox for 'Active' only. But my requirement is to display a check box for Inactive as well even though inactive records are not present in grid and when the user click on Inactive check box, we should load Inactive projects also to the project. Can someone please assist with this.
Thank you Andrew for all your guidance in this, it really helped!
Hello Naveen,
I am glad that the GetDescendantFromName method is working to hook up your command in this case.
It is worth noting that in the sample project I had sent you, the FilterSelectionControl's Loaded event will fire at the start of the project, but the ItemsSource will likely be null. I would recommend checking for this, as I feel this could possibly be why your ListBox is showing up empty.
It is also possible that this could be a timing issue, and the ListBox simply isn't populated at the time that you are trying to get it. If this is the case, I would recommend continuing the Dispatcher.BeginInvoke action like before, but add a DispatcherPriority parameter to that method call to add a little bit more delay so that the ListBox is hopefully populated at that point. For example, usage of a "Background" DispatcherPriority could look like the following:
Dispatcher.BeginInvoke(new Action(() => {
//Code here
}), DispatcherPriority.Background);
There are a few different DispatcherPriority enumerations, and you can read about them and decide which may be best for your situation here: https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcherpriority(v=vs.110).aspx.
I hope this helps. Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Thanks Andrew!
I tried hooking up my own command to click event of button using GetDescendantFromName method, it works fine with your example.
But when I try to do the same in my application, GetDescendantFromName method is returning null for itemBox when the application is initially loaded and after clicking on filter icon for multiple times, it did return listbox but an empty one and FilterValueProxy item for adding INACTIVE checkbox is not getting added to the list. I am using the same source code
Normally I would recommend the Filtered or Filtering events of the XamGrid for this - and this would work if you are unchecking the "Active" filter and leaving the "Inactive" filter checked, but if you keep the "Active" filter checked and try to just check the "Inactive" filter, you may have issues with this. The reason for this is because since there aren't really any "Inactive" records in your grid, the filter isn't really "changing."
Instead, I would recommend that to override the command fired by the "Ok" button, that you include the default style for the FilterSelectionControl and use this with the XamGrid.FilteringSettings.FilterSelectionControlStyle property instead. This default style can be found in the generic.shared.xaml file commonly found at the following directory:
C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\XamGrid
Once you have included this style and any resource dependencies it may have, you can check the ControlTemplate of this style for a Button named "AcceptButton" toward the end of the style. This is the "Ok" button for the filter drop-down, and you can hook your own command or click event to it in order to invoke your service to pull in your "Inactive" projects.
It also may be possible to throttle the Loaded event mentioned in a previous update to get this "AcceptButton" as well using the Infragistics.Windows.Utilities class in the same way as was done to obtain the ListBox. For example, you may be able to do the following:
Button button = Utilities.GetDescendantFromName(control, "AcceptButton") as Button;
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
Thanks Andrew! Great! This is exactly what I want, but can we populate inactive records on click of Ok button inside filter instead of having a new button outside grid, this kills the very purpose of having Inactive checkbox in filter in my case as for populating inactive records on click of button outside grid we don't really need Inactive checkbox inside filter. Can we override Ok button command somehow and invoke a service from there? Thanks again!