Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

MVVM. How to sort column of a BindingListWithRemoving

$
0
0

in my MVVM application, I have a class Users (Model) and its corresponding UsersViewModel (ViewModel). I wish to display a collection of UsersViewModel items in a DataGrid

<DataGridName="dgUsers"CanUserAddRows="True"CanUserDeleteRows="True"AutoGenerateColumns="False"CanUserReorderColumns="True"CanUserSortColumns="True"ItemsSource="{Binding Path=ListUsers}"SelectedItem="{Binding Path=User,Mode=TwoWay}"><DataGrid.Columns>
                   .....</DataGrid.Columns></DataGrid>

In ViewModel I created a BindingListWithRemoving to manage the UsersViewModel collection.

Private _user asUsersViewModelPublicPropertyUserasUsersViewModelGetReturn _userEndGetSet(ByVal value asUsersViewModel)
       _user = valueNotifyPropertyChange("User")EndSetEndPropertyPrivate _listUsers AsBindingListWithRemoving(OfUsersViewModel)PublicReadOnlyPropertyListUsers()AsBindingListWithRemoving(OfUsersViewModel)GetIf _listUsersIs NothingThen
                _listUsers=NewBindingListWithRemoving(OfUsersViewModel)()AddHandler _listUsers.AddingNew,ListUsersAddingNewHandlerAddHandler _listUsers.BeforeRemove,ListUsersBeforeRemoveHandlerForEach u AsUsersInDataContext.UsersDim newUserVM AsNewUsersViewModel(u)
                    _listUsers.Add(newUserVM )Next
                _user = _listUsers.FirstOrDefaultEndIfReturn _listUsersEndGetEndProperty....

insert, delete and update of rows works, but sorting data by Columns does not. How can I resolve this issue?

thanks


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>