Grid has fields A1 A2 A3 and A4. Requirement is to highlight records that meet a dynamically changing selection criteria.
So, for example, if selection criteria is (A1 == 10 & A4 == 30), then all records that meet the criteria need to be highlighted. Later, when the criteria changes to something completely different, the new set of record meeting that criteria are highlighted instead.
The idea is to show all records at all times but highlight only the ones that meet the current criteria .
- Anything built-in in Grid to help me with this
- If not, is my only option to just iterate over the entire row collection, examine each record to meet the new criteria and set the highlighting?
Thanks!
There are a couple of ways you can do this. Neither of thm require you to loop over all the rows in the grid. :)
One approach would be to use row filtering. Normally, filtering on the grid hides the filtered out rows and only shows the rows that meet the filter criteria. But you can change this so that it simply applies an appearance to the row. What you would do is set RowFilterAction on the Override to ApearancesOnly. Then you can set the FilteredInRowAppearance. And apply filters to the grid using the ColumnFilters collection on the band - or even let the user filter the data however they want by setting AllowRowFiltering.
Another option would be to simply use the InitializeRow event of the grid. You can examine the row and see if it meets your current filter criteria and then either apply an appearance to the row or clear it. If you want to take this route, I recommend that you check out the WinGrid Performance Guide for some advice on the most efficient way to do it.
Oh... I almost forgot. If you go with the second method, you will need to call grid.Rows.Refresh(FireInitializeRow) whenever your criteria changes so the event will fire again.
Mike Saltzman"]One approach would be to use row filtering. Normally, filtering on the grid hides the filtered out rows and only shows the rows that meet the filter criteria. But you can change this so that it simply applies an appearance to the row. What you would do is set RowFilterAction on the Override to ApearancesOnly. Then you can set the FilteredInRowAppearance. And apply filters to the grid using the ColumnFilters collection on the band - or even let the user filter the data however they want by setting AllowRowFiltering.
Using RowFilterAction as AppearancesOnly is a truly wonderful idea. I did not know such a capability existed. Before implementing it, I have a question. I told you the system would generate some dynamic selection criteria (A ==10 && D == 30) that can change over time. I want to show rows matching that condition to appear differently. Would setting RowFilterAction to ApearancesOnly also apply to user's manual filtering action? So, for example, if user manually sets filter B == 20, would the grid show rows with B == 20 using FilteredInRowAppearance OR would rows with B != 20 disappear from grid? I want the latter behavior (rows not meeting condition to disappear) when user's filteriing action. However, when system generated selection criteria, I want to use your suggestion. Are both possible?
vrn said:Would setting RowFilterAction to ApearancesOnly also apply to user's manual filtering action?
Yes, the filter action applies to all filtering. You can't do some filtering using the appearance and some using hiding.
So it sounds like this method won't work for you and you will need to use the InitializeRow event to do the system-generated coloring of rows.