Click here to Skip to main content
15,916,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had a research by criteria with Two combobox, it works fine after the research is finished, I have a button Display All : to reset the combobox to null..and the DataGrid display with all elements ,

The problem that the combobox must be empty when I click on the Button Dispaly All!

1) Without select an element in combobox(just dispaly the datagrid):I have 6 elements in the datagrid, it is correct..and the combobox are Empty.

2) After select the Search criteria, i have the result correct: (I have just 3 results, it is the correct action)

3) When I click on the button Display All:(I have all the elements in datagrid, 6 elements..It is correct) But the Combobox aren't empty!!

The view:


The ViewModel:


What I have tried:

XML
<pre>    <Window x:Class="WPFAuthentification.Views.BusinesseventsView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" >   

     <Label Content="Entity Type" Width="128" Grid.Row="1" Grid.ColumnSpan="2"/>
     <ComboBox HorizontalAlignment="Center" VerticalAlignment="Center"  
         ItemsSource="{Binding EntityLevelEnum}" 
        SelectedItem="{Binding EntityType, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True, TargetNullValue=''}"
        Grid.ColumnSpan="2" Grid.Column="1"  />


        <Button Content="Dislplay all" ToolTip="Display All Business Events" 
                VerticalAlignment="Top"  Command="{Binding Initialize}" 
                Visibility="{Binding Path=ShowDisplayAllButton, Converter={StaticResource BoolToVis}}"  />

         <DataGrid ..... />
    </Window>


C#
<pre>    class BusinesseventsViewModel : ViewModelBase1
    {

        private ObservableCollection<BusinessEventClass> businessEventsList;    

        private RelayCommand<string> initialize;
        public RelayCommand<string> Initialize
        {
            get { return initialize; }
        }       
        public BusinesseventsViewModel()
        {
            //businessEventsList: to Get all the Business events
            businessEventsList = new ObservableCollection<BusinessEventClass>(WCFclient.getAllBusinessEvent());
            //Enumeration of Entity Type and Criticality
            levelCriticalityEnum = new ObservableCollection<Level_Criticality>(Enum.GetValues(typeof(Level_Criticality)).Cast<Level_Criticality>());
            entityLevelEnum = new ObservableCollection<BusinessEntityLevel>(Enum.GetValues(typeof(BusinessEntityLevel)).Cast<BusinessEntityLevel>());
            //the Button Display All :
            initialize = new RelayCommand<string>(initFunc);    
       }        

       //Function of the Button Display All
        private void initFunc(object obj)
        {
      entityLevelEnum.Clear();
          //  EntityLevelEnum = null;
            levelCriticalityEnum.Clear();
            //LevelCriticalityEnum = null;
            OnPropertyChanged("EntityLevelEnum");
            OnPropertyChanged("LevelCriticalityEnum");    
			}     

         private string  entityType;
        public string EntityType
        {
            get { return entityType; }
            set
            {
                entityType = value;
                businessEventsList = filterByCriteria(entityType, criticality);
                OnPropertyChanged("BusinessEventsList");
                OnPropertyChanged("EntityType");
            }
        } 

             //Function of the research :
                 public ObservableCollection<BusinessEventClass> filterByCriteria(string entityType, string criticality)
        {               
            BusinessEventsList = new ObservableCollection<BusinessEventClass>(WCFclient.getAllBusinessEvent());         

            ObservableCollection<BusinessEventClass> updatedList = new ObservableCollection<BusinessEventClass>();

            if ((entityType == null) && (Criticality == null))
            {
                updatedList = businessEventsList;
                levelCriticalityEnum = new ObservableCollection<Level_Criticality>(Enum.GetValues(typeof(Level_Criticality)).Cast<Level_Criticality>());     
                 entityLevelEnum = new ObservableCollection<BusinessEntityLevel>(Enum.GetValues(typeof(BusinessEntityLevel)).Cast<BusinessEntityLevel>());

            }          

            if ((entityType != null && entityType != "") && (Criticality != null))
                {
                    updatedList = new ObservableCollection<BusinessEventClass>(BusinessEventsList.Where(a => a.EntityType.ToString().ToLower().Equals(criticality.ToString())
                                                                             && a.Critciality.ToString().Equals(criticality.ToString())));
                } }
Posted
Updated 1-Aug-17 0:16am
v3

Expose BusinessEventsList as a public property. To clear, call BusinessEventsList.Clear. Newing the BusinessEventsList collection will break the binding.

If you want to switch sources for the BusinessEventsList, then expose a CollectionViewSource property and bind to the View.
C#
public CollectionViewSource BusinessEventsListCVS { get; private set; }
XML
<ComboBox ItemsSource="{Binding BusinessEventsListCVS.View}" />
 
Share this answer
 
Thanks for your help,
I find the solution:
comboboxname.SelectedIndex = - 1;
in code behind

XML
private void DisplayAll_Clickk(object sender, RoutedEventArgs e)
        {    //comboCodeType : name of combobox for the EntityType
            comboCodeType.SelectedIndex = -1;
             //comboType: name of combobox for the Criticality
            comboType.SelectedIndex = -1;
        }


It works fine.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900