I have a View ConfigRole which contains DataGrid with two Columns: View and IsEnabled(CheckBox), and a Search area.
and the Button Save it works correctly, I make all views which I want IsEnabled and I save it : for exemple:

And when I use the search box, I have the correct result for all the views I search on it,for exemple I write 'Customer' in search box ,I have all the views with the key 'Customer':

My problem is when I make Save Button after Search ,all the CheckBox (IsEnabled in the first View will be FALSE !! just the Views I make it Enabled in the Search view are Save !
XAML ConfigRole:
- <TextBox x:Name="textBox" Text="{Binding ViewName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
- NotifyOnValidationError=True ,TargetNullValue=''}" />
- <DataGrid x:Name="dataGrid" SelectedItem="{Binding SelectedView}" ItemsSource="{Binding ViewList}"
- CanUserAddRows="False" AlternationCount="2" AlternatingRowBackground="Blue" AutoGenerateColumns="False" >
- <DataGrid.Columns>
- <DataGridTextColumn Header="View" Binding="{Binding ViewCode}" IsReadOnly="True" />
- <DataGridTemplateColumn Header="Is Enabled" Width="Auto">
- <DataGridTemplateColumn.CellTemplate>
- <DataTemplate>
- <CheckBox IsChecked="{Binding IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
- DataTemplate>
- DataGridTemplateColumn.CellTemplate>
- DataGridTemplateColumn>
- DataGrid.Columns>
- DataGrid>
- lt;Button Command="{Binding SaveRole}" Visibility="{Binding Path=ShowSaveButton, Converter={StaticResource BoolToVis}}" CommandParameter="{Binding ElementName=ConfigureRole}"/>
- Grid>
ConfigRoleViewModel:
- private ObservableCollection
_viewList; - private MiniTasServicesClient WCFclient = new MiniTasServicesClient();
- public int test;
- public ConfigRoleModel(int RoleId,ObservableCollection
roleList) - {
- test = RoleId;
- _viewList = new ObservableCollection
(WCFclient.getViewRoleMapsByRole(RoleId)); - saveRole = new RelayCommand
(configRole); - }
- private RelayCommand
saveRole; - public RelayCommand
SaveRole - {
- get { return saveRole; }
- }
- //all list of Views
- public ObservableCollection
ViewList - {
- get { return _viewList; }
- set
- {
- _viewList = value;
- OnPropertyChanged("ViewList");
- }
- }
- //the Function of the Button Save
- private void configRole(Window window)
- {
- List
listViewRoleMap = new List (); - foreach (ViewRoleMapClass view in ViewList)
- {
- if (view.IsEnabled) listViewRoleMap.Add(view);
- }
- int resultUpdate = WCFclient.updateViewRoleMap(listViewRoleMap, test);
- if (resultUpdate == 0)
- {
- string sCaption = "Save notification";
- string sInformation = "Save operation is performed successfully";
- MessageBoxButton btnMessageBox = MessageBoxButton.OK;
- MessageBoxImage icnMessageBox = MessageBoxImage.Information;
- MessageBoxResult rsltMessageBox = MessageBox.Show(sInformation, sCaption, btnMessageBox, icnMessageBox);
- }
- _refreshList();
- }
- //Search
- private string _viewName;
- public string ViewName
- {
- get { return _viewName; }
- set
- {
- _viewName = value;
- OnPropertyChanged("ViewName");
- _viewList = searchByCriteria(ViewName);
- OnPropertyChanged("ViewList");
- }
- }
- private ObservableCollection
searchByCriteria( string _viewName) - {
- List
resultSearch=new List (); - _viewList = new ObservableCollection
(WCFclient.getViewRoleMapsByRole(test)); - if (_viewName != null)
- {
- resultSearch = _viewList.Where(c => c.ViewCode.ToLower().Contains(_viewName.ToLower())).ToList();
- }
- return new ObservableCollection
(resultSearch); - }
How can I fix it?
Thanks,
Rajkiran SwainPosted Jun 19, 2017, 6:11 AM