I have the following Grid.
Hi Sumit,
There's no built-in way to do this, but there are a number of ways you can customize the filtering.
Just to make sure I understand what you want... basically, you want to filter such that any GroupByRow which has a visible child row will keep all of it's child rows visible. So if you filtered by "SubAcc1", you would end up with this:
Hi Mike,
I have come up with the following solution so far.
Here is my Code that I have written to handle the AfterRowFilterChanged event of the grid. What I am doing is to get the IDs from all the filtered rows and after that I remove the filter from account and show the rows based on the IDs. The code is crud but I hope it would give you the basic idea of what I am trying to do.
private void grdData_AfterRowFilterChanged(object sender, AfterRowFilterChangedEventArgs e){ //Check whether filter is applied on Account. if (e.Column.Key.Equals("Account")) { //Here Set Hidden property to false for each row of grid foreach (UltraGridGroupByRow row in grdData.Rows) row.Hidden = false; List<string> lstForVisible = new List<string>(); //Get filtered rows IDs. foreach (UltraGridRow r in e.Rows.GetFilteredInNonGroupByRows()) lstForVisible.Add(Convert.ToString(r.GetCellValue("Id"))); //Remove Sub Account filter. grdData.DisplayLayout.Bands[0].ColumnFilters["Account"].ClearFilterConditions(); //Set Hidden Property to true for filered rows. List<string> lstForVisible = new List<string>(); UltraGridColumn ccolumn = grdData.DisplayLayout.Bands[0].Columns["Id"]; foreach (UltraGridGroupByRow row in grdData.Rows) { bool isHide = true; foreach (string str in lstForVisible) { string fr = Convert.ToString(row.Value); if (fr.Equals(str)) { isHide = false; break; } } if (isHide.Equals(true)) row.Hidden = true; } } }
Please provide me with any sample code of the solution you are suggesting, if possible.
With the above approach I am facing the following problem:
After the solution I apply, the filter is removed from the account column and if user selects 'ALL' option from account filter then event is not fired.I need a way by which this event can be fired on clicking the 'ALL' option from account filter.
Hi,
The filters are removed because your code is removing them by calling ClearFilterConditions. Since there are no filters applied, selecting "All" is not a change, and so doesn't fire the events.
Presumably, you are doing that because you don't want the grid filters to do anything, since you want to handle the filtering yourself. But that's not the way to do it. You don't want to remove the filters, you want the grid to keep them, but not actually do anything or hide any rows.
To achieve that, you do this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridOverride ov = layout.Override; ov.RowFilterAction = RowFilterAction.None; }
Alternatively, you might want to consider using:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridOverride ov = layout.Override; ov.RowFilterAction = RowFilterAction.AppearancesOnly; ov.FilteredInRowAppearance.BackColor = Color.Red; ov.FilteredInRowAppearance.ForeColor = Color.White; }
This way, the rows with the matching Account are highlighted, in addition to hiding the GroupByRows that don't contain data rows with that account.
The solution you are providing would be applicable to all the columns. I want this functionality for only one column because applying filtering using code on all the columns would be a time taking task.
I am just curious to know something about the piece of code I have posted earlier. I understand that I am removing all filters using code, that is why no event is getting fired when we click the "All" option from the filter drop down. I just want to know if there is something I can do to get the text of the option I have selected from the filter drop down, even after clearing all the filters. For example: If I select "All" from the filter drop down (after clearing all the filters), I get the text "All" in my code. I would really appreciate if you could provide me with a sample solution.
The only way to do that would be to store the value of the filter before you clear it. Once you clear the filters, that text is lost from the grid. You will not be able to populate the filter cell with that text without also re-applying the filter to the grid, though.
You are correct, though - the approach I am taking will apply to every column. But I don't see any way to apply it to just the one column without applying it to all of the others - unless you handle all of the filtering yourself. You could take the same approach I used here and then, in addition to that, you could also loop through the ColumnFilters and evaluate them by calling MeetsCriteria on each FilterCondition applied to the row. This could get pretty complicated, though. You will essentially have to re-implement all of the filtering logic in the grid to handle the LogicalOperators and such.
It might be easier to simple put a TextBox or some other UI outside of the grid specifically for the purposes of filtering the GroupByRows how you want.