Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: CheckComboBox enqueries

$
0
0
Hi,

1) to start the CheckComboBox with selectedItems, you can set the SelectedItemsOverride property :
 List<string> myList = new List<string>() { "abc", "def", "ghi", "jkl" };
      _checkComboBox.ItemsSource = myList;
      _checkComboBox.SelectedItemsOverride = new List<string>() { myList[ 0 ], myList[1] };
or set the SelectecValue property ;
 List<string> myList = new List<string>() { "abc", "def", "ghi", "jkl" };
      _checkComboBox.ItemsSource = myList;
      _checkComboBox.SelectedValue = "abc,def";
2) The check is removed in the CheckListBox because you clear the CheckList and fill it with new items. If you find a way to re-use the same object for filling the CheckListBox, it should work, Here's an example :
 public partial class MainWindow : Window
  {
    List<DataObject> DataObjectList = new List<DataObject>()
    {
      new DataObject( "A" ),
      new DataObject( "B" ),
      new DataObject( "C" ),
      new DataObject( "D" ),
      new DataObject( "E" ),
      new DataObject( "F" ),
      new DataObject( "G" ),
      new DataObject( "H" ),
      new DataObject( "I" ),
      new DataObject( "J" ),
      new DataObject( "K" ),
      new DataObject( "L" )
    };

    public MainWindow()
    {
      InitializeComponent();

      List<string> myList = new List<string>() { "abc", "def", "ghi", "jkl" };
      _checkComboBox.ItemsSource = myList;
    }

    private void CheckComboBox_CostCenter_ItemSelectionChanged( object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e )
    {
      _checkListBox.Items.Clear();
      int SelectedItemsTotal = _checkComboBox.SelectedItems.Count;
      string[] selectedCostCenter = new string[ SelectedItemsTotal ];

      for( int j = 0; j < SelectedItemsTotal; j++ )
      {
        selectedCostCenter[ j ] = _checkComboBox.SelectedItems[ j ].ToString();
        if( selectedCostCenter[ j ] == "abc" )
        {
          _checkListBox.Items.Add( DataObjectList[ 0 ] );
          _checkListBox.Items.Add( DataObjectList[ 1 ] );
          _checkListBox.Items.Add( DataObjectList[ 2 ] );
        }
        else if( selectedCostCenter[ j ] == "def" )
        {
          _checkListBox.Items.Add( DataObjectList[ 3 ] );
          _checkListBox.Items.Add( DataObjectList[ 4 ] );
          _checkListBox.Items.Add( DataObjectList[ 5 ] );
        }
        else if( selectedCostCenter[ j ] == "ghi" )
        {
          _checkListBox.Items.Add( DataObjectList[ 6 ] );
          _checkListBox.Items.Add( DataObjectList[ 7 ] );
          _checkListBox.Items.Add( DataObjectList[ 8 ] );
        }
        else if( selectedCostCenter[ j ] == "jkl" )
        {
          _checkListBox.Items.Add( DataObjectList[ 9 ] );
          _checkListBox.Items.Add( DataObjectList[ 10 ] );
          _checkListBox.Items.Add( DataObjectList[ 11 ] );
        }
      }
    }
  }

  public class DataObject
  {
    public DataObject( string data )
    {
      this.Data = data;
    }

    public string Data
    {
      get;
      set;
    }

    public override string ToString()
    {
      return this.Data;
    }
  }
Here's another way of doing the CheckComboBox_CostCenter_ItemSelectionChanged method without clearing the CheckListBox:
 private void CheckComboBox_CostCenter_ItemSelectionChanged( object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e )
    {
      if( e.IsSelected )
      {
        if( e.Item.ToString() == "abc" )
        {
          _checkListBox.Items.Add( DataObjectList[ 0 ] );
          _checkListBox.Items.Add( DataObjectList[ 1 ] );
          _checkListBox.Items.Add( DataObjectList[ 2 ] );
        }
        else if( e.Item.ToString() == "def" )
        {
          _checkListBox.Items.Add( DataObjectList[ 3 ] );
          _checkListBox.Items.Add( DataObjectList[ 4 ] );
          _checkListBox.Items.Add( DataObjectList[ 5 ] );
        }
        else if( e.Item.ToString() == "ghi" )
        {
          _checkListBox.Items.Add( DataObjectList[ 6 ] );
          _checkListBox.Items.Add( DataObjectList[ 7 ] );
          _checkListBox.Items.Add( DataObjectList[ 8 ] );
        }
        else if( e.Item.ToString() == "jkl" )
        {
          _checkListBox.Items.Add( DataObjectList[ 9 ] );
          _checkListBox.Items.Add( DataObjectList[ 10 ] );
          _checkListBox.Items.Add( DataObjectList[ 11 ] );
        }
      }
      else
      {
        if( e.Item.ToString() == "abc" )
        {
          _checkListBox.Items.Remove( DataObjectList[ 0 ] );
          _checkListBox.Items.Remove( DataObjectList[ 1 ] );
          _checkListBox.Items.Remove( DataObjectList[ 2 ] );
        }
        else if( e.Item.ToString() == "def" )
        {
          _checkListBox.Items.Remove( DataObjectList[ 3 ] );
          _checkListBox.Items.Remove( DataObjectList[ 4 ] );
          _checkListBox.Items.Remove( DataObjectList[ 5 ] );
        }
        else if( e.Item.ToString() == "ghi" )
        {
          _checkListBox.Items.Remove( DataObjectList[ 6 ] );
          _checkListBox.Items.Remove( DataObjectList[ 7 ] );
          _checkListBox.Items.Remove( DataObjectList[ 8 ] );
        }
        else if( e.Item.ToString() == "jkl" )
        {
          _checkListBox.Items.Remove( DataObjectList[ 9 ] );
          _checkListBox.Items.Remove( DataObjectList[ 10 ] );
          _checkListBox.Items.Remove( DataObjectList[ 11 ] );
        }
      }
    }

Viewing all articles
Browse latest Browse all 4964

Latest Images

Trending Articles



Latest Images

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