This project has moved. For the latest updates, please go here.

select all item in checkcombobox

Developer
Feb 20, 2015 at 12:29 PM
Based on comment :
"How to select all item in checkcombobox by clicking select all item which is in checkcombobox....
any idea about that"
Developer
Feb 20, 2015 at 12:55 PM
Hi,
Try this :
<xctk:CheckComboBox x:Name="_checkComboBox"
                          ItemsSource="{Binding MyData}"
                          ItemSelectionChanged="_checkComboBox_ItemSelectionChanged_1"
                          Width="250"
                          Height="25"/>

public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();

      _checkComboBox.DataContext = this;

      this.MyData = new ObservableCollection<string>()
      {
        "First", "Second", "Third", "Fourth", "Fifth", "SelectAll"
      };
    }

    public ObservableCollection<string> MyData
    {
      get;
      set;
    }

    private void _checkComboBox_ItemSelectionChanged_1( object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e )
    {
      var checkComboBox = sender as CheckComboBox;
      if( checkComboBox != null )
      {
        if( e.IsSelected && object.Equals( e.Item, this.MyData.Last() ) )
        {
          checkComboBox.SelectedItemsOverride = new ObservableCollection<string>( this.MyData );
        }
        else if( !e.IsSelected )
        {
          if( checkComboBox.SelectedItems.Contains( this.MyData.Last() ) )
          {
            checkComboBox.SelectedItems.Remove( this.MyData.Last() );
          }
        }
      }
    }
  }