Hi,
The objects bound to each row in the XamGrid has a bool property which specifies whether or not the row should be visible. How do I bind this to the visibility of the row?
Also, this bool property would change dynamically (the object implements INotifyPropertyChanged) and I would want the row's visibility to be updated accordingly, dynamically.
Can you suggest how this can be implemented?
Are there any issues will hiding rows in general like this? Would scrolling still be smooth, etc.?
Thanks
Filtering doesn't listen to INotifyPropertyChanged, simply b/c if we did so, we'd have to walk your entire dataSource, and hook up an event to each item.
So, if you know that your data has changed, you can let the xamGrid know by calling the InvalidateData method off of the xamGrid.
xamGrid1.InvalidateData();
I hope this helps.
-SteveZ
Stephen,
Thanks. That seems to work, but not fully. When the bound property value (based on which filter is setup) changes, the grid doesn't seem to automatically show/hide the row. I have to reset the filter every time a value changes, which wouldn't work. Please let me know how to make the grid respond to property value changes and show/hide rows automatically.
Bhadri
Code:
The bound object type is like this:
// This does not implement INotifyPropertyChanged, but the proeperty is a DependencyProperty
class MyObjectType : FrameworkElement
{
public Visibility IsVisible{get;set;} // This is a DependencyProperty
}
And this filter setting works:
Column col = (Column)xamGrid.Columns["IsVisible"];
// Create new RowsFilter object
//Create new ComparsionCondition, specifying values must be greater than 15
compCond.Operator =
ComparisonOperator.Equals;
compCond.FilterValue =
Visibility.Visible;
//Add condition to the RowFilter
rf.Conditions.Add(compCond);
//Add RowFilter to the RowFiltersCollection
xamGrid.FilteringSettings.RowFiltersCollection.Clear();
xamGrid.FilteringSettings.RowFiltersCollection.Add(rf);
After thinking about this further, you could just add a hidden column for your Visibility property, and filter on it.
That way, all rows that are collapsed, can be removed.
You could apply the filter in the codebehind, so the users wouldn't know you had one applied:
http://help.infragistics.com/NetAdvantage/Silverlight/2010.3/CLR4.0/?page=SL_xamGrid_Programmatically_Create_a_Filter.html
-Stevez
Another suggestion is to have a seperate "VisibleObjects" collection that represents just those data objects you want the grid to show. Your app could update that collection, adding or removing objects based on the value of the bool property. As long as that collection is observable, the grid will automatically respond to the changes in that collection.
Devin
Ok. Do I have to parse through the entire Row collection to find the matching Row? That's actually very expensive and wouldn't work as we are planning to bind this to 1000s of rows and we could also show/hide 1000s of rows at a time.