In version 8.1 it seems that xamDataGrid ignore the Filter on the DefaultView
ICollectionView view = CollectionViewSource.GetDefaultView(this.ItemsSource); if (view != null) { view.Filter += (obj) => { return obj.ToString() == "Hello World"; }; } view.Refresh();
Anyone manage to get this working? It work fine using a ListBox.
I was excited about the idea of using the visibility trick, but I just don't see it working for me. So sad.
My design is to not have a checkbox for the deleted property. I want a simply delete button to delete selected items. As such, the EditModeEnded event never comes into play.
Because I'm using mementos during the edit cycle, I ended up with the following scenario:
1. Take a snapshot of the data source into a duplicate collection.
2. Bind to that collection.
3. When deleting rows, simply remove them from the data source.
Upon committing changes:
4. Enumerate the WORKING data set.
a. Apply changes to each original object that exists in both collections via mementos from the working objects.
b. Add objects that are in the working set, but not the original set.
5. Enumerate the ORIGINAL data set.
a. Mark any records as deleted that are no longer in the working set.
6. Persist the original set to the DB.
A LOT OF WORK!!!
I appreciate your efforts, Alex. You've been a great asset on the forum!
I am not sure you will be able to use a binding in this scenario. If it is acceptable to use code-behind, you could handle the EditModeEnded event and mark the record for deletion :
void xamDataGrid1_EditModeEnded(object sender, EditModeEndedEventArgs e)
{
if (e.Cell.Field.Name == "Boolean" && false.Equals((bool)e.Cell.Value))
e.Cell.Record.Visibility = System.Windows.Visibility.Collapsed;
e.Cell.Record.Tag = "ReadyForDeletion";
}
As the record's visibility could be set to collapsed by some other operation, you could also use the Tag property. When the user confirms the deletion, you can get these records :
private void button1_Click(object sender, RoutedEventArgs e)
var recordsToDelete = xamDataGrid1.Records.Where(x => x.Visibility == System.Windows.Visibility.Collapsed).ToList<Record>();
var recordsToDelete1 = xamDataGrid1.Records.Where(x => x.Tag!=null && x.Tag.ToString() == "ReadyForDeletion").ToList<Record>();
System.Diagnostics.Debug.WriteLine(recordsToDelete.Count.ToString());
System.Diagnostics.Debug.WriteLine(recordsToDelete1.Count.ToString());
and delete them from the data source. Casting the record to DataRecord will expose the underlying object through the DataItem property.
Hiding the records sounds like an elgant way to do this, but I'm not sure if it's possible.
From previous posts, I'm told that I can't use a style because the visiblity is explicitly set locally.
So is there a way to bind the visibility of a row to a property of the dataitem?
Would hiding the records in the XamDataGrid be acceptable in your scenario? You can do this by setting the Record's Visibility property and you can hide them until the user clicks OK.
Hi Alex,
I'm temporarily stuck with 8.2 (need to get through the initial delivery first) and need a way to filter out rows.
I have a delete button that lets the user delete the selected rows. This marks each object in the BindingList<> that the grid's bound to for deletion (IsActive).
I need to have the grid remove those rows immediately (filtered view to those objects with IsActive == True) and I'm not sure how to do this. There are no DataItems in the grid ... rather, the DataSource contains the collection. I can't simply remove them from the datasource, because when the user finally hits OK to commit, that source drives the DB updates.
What are my options? Thanks!