This is a migrated thread and some comments may be shown as answers.

MVVM Filtered + Filtering Event

1 Answer 76 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 25 Feb 2016, 05:23 PM

Hi, when using the GridViewSelectColumn filters, it deselects the selecteditems. So I use this bit of code to fix it 

 

private void LoanGrid_OnFiltered(object sender, GridViewFilteredEventArgs e)
{
    LoanGrid.SelectedItems.AddRange(SelectedLoans);
}
         
public BindableCollection<LoanDTO> SelectedLoans { get; set; }
         
private void LoanGrid_OnFiltering(object sender, GridViewFilteringEventArgs e)
{
    SelectedLoans = new BindableCollection<LoanDTO>();
    foreach (var selectedItem in LoanGrid.SelectedItems)
    {
        SelectedLoans.Add((LoanDTO)selectedItem);
    }
}

That works perfectly fine, but I'm trying to have it be in MVVM format using caliburn.

on xaml side,     cal:Message.Attach="[Filtered] = [Filtered];[Filtering] = [Filtering] "

ViewModel

 

private BindableCollection<LoanDTO> _oldLoans = new BindableCollection<LoanDTO>();
 
public void Filtered()
{
    SelectedLoans = new BindableCollection<LoanDTO>(Items.Where(x => _oldLoans.Any(y => y.Id == x.Id)));
}
 
public void Filtering()
{
    _oldLoans = new BindableCollection<LoanDTO>();
    foreach (var selectedItem in SelectedLoans)
    {
        _oldLoans.Add(selectedItem);
    }
}

 

The selecteditems get cleared using the MVVM methods. Any thoughts?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Mar 2016, 09:44 AM
Hi Minh,

In order to handle a given event using the MVVM pattern, you can benefit from the EventToCommandBehavior mechanism. Can you please check it out and let me know how it goes?

Regards,
Stefan X1
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Minh
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or