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
So currently, the only way to a hide a row is to set the Height for a particular row to 0. However, you can't bind to that property.
So basically you'd have to hook into the INotifyPropertyChanged of your collection. When the row's value changes you'll need to find the row it's associated with, and update its height. To reset it, you can set the Height property to null.
-SteveZ
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.
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
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);
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.