question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access Selected Items in CheckComboBox

See original GitHub issue

I try to access to the Selected Items of the CheckComboBox. The goal is, to be able to selected Columns of a Table that you want to show. It seem like there is no way to do it in a MVVM achitecture.

The first way I was thinking is : <hc:CheckComboBox SelectedItems="{Binding MySelectedList}" /> but according to the issue #485 the SelectedItems is not a Property.

I found another way that not working but suppose to ^^. It is to create a class Item with 2 properties : Name and Selected and link them to the Property DisplayMemberPath and SelectedValuePath, see example below :

Model/Item.cs

public class Item{
        public string Name { get; set; }
        public bool Selected { get; set; }
}

ViewModel/MainWindowViewModel.cs

public class MainWindowViewModel{
        public ObservableCollections<Item> MyItemList { get; set; } = new  ObservableCollections<Item>() {
                new Item() { Name = "column", Selected = true},
                new Item() { Name = "column", Selected = true},
                new Item() { Name = "column", Selected = false},
                new Item() { Name = "column", Selected = false},
        }
}

View/MainWindow.xaml

<hc:CheckComboBox Width="300" ItemsSource="{Binding MyItemList }" ShowClearButton="True" 
ShowSelectAllButton="True" MaxHeight="30" DisplayMemberPath="Name" SelectedValuePath="Selected"/>

Is there a way to access to Selected Items without using the code behind (.xaml.cs) ? Is there an improvement to make in the CheckComboBox ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Yoplercommented, Feb 9, 2022

Hi 🖐,

Here a little exemple how I make it work :

MainWindow.xaml.cs :

public partial class MainWindow : Window
    {
        public List<Item> Items { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;

            Items = new List<Item>();
            for (int i = 0; i < 15; i++)
                Items.Add(new Item($"Item {i}", i));

            // Here CheckComboBox refer to the hc:CheckComboBox x:Name="CheckComboBox"
            CheckComboBox.ItemsSource = Items;

            // Here, I select the first three items
            for (int i = 0; i < 3; i++)
                CheckComboBox.SelectedItems.Add(Items[i]);
            
        }

        private void CheckComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            foreach (Item item in e.AddedItems)
                // For on each add Items
                // do what you want
            foreach (Item item in e.RemovedItems)
                // For on each removed Items
                // do what you want
        }
}

and the xaml : MainWindow.xaml :

<Window x:Class="Wpf_Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Wpf_Test" 
        xmlns:hc="https://handyorg.github.io/handycontrol"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800"
        Background="Gray">
    <StackPanel>
        <hc:CheckComboBox x:Name="CheckComboBox"
                      SelectionChanged="CheckComboBox_SelectionChanged"
                      DisplayMemberPath="Name"
                      ShowClearButton="True"
                      ShowSelectAllButton="True"/>
    </StackPanel>
</Window>

Hope it can help !

0reactions
NaBiancommented, Sep 3, 2022

closed in 7519c7e

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set Items Selected in a CheckComboBox
I´m using the CheckComboBox by ControlsFX for a Project and I want to set some of the Items Checked from the Start so...
Read more >
How to get selected values in CheckComboBox emulation ...
Use the ASPxDropDownEdit.FindControl method to get ASPxListBox and the ASPxListBox.SelectedValues property to get selected values. See also: ...
Read more >
ComboBox.SelectedItem Property (System.Windows.Forms)
Gets or sets currently selected item in the ComboBox.
Read more >
How to use CheckComboBox in JavaFX? - YouTube
In this video tutorial, you will learn how to use controlsFX API-based CheckComboBox. It is very useful to control, here we have items...
Read more >
Select all feature in CheckCombobox
Here's how : Use you own CheckComboBox to overwrite the UpdateText() method and not display the “Select All” as a selected item in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found