Introduction:
Recently, in our project we wanted to allow the user to select multiple values in a list. But the list should be populated inside a grid row. So we don't want to use a listbox and also we are not interested in third-party tools. Instead of that, we wanted to use a multiselect combobox. When I browsed through various blogs, forums, etc. I got some good code, but none of them are easy for me to understand and implement so I decided to move with something bit tricky but easy for you. In short, below you will find a MultiSelect Combobox with Search feature on elements.
Using the code:
In the the below screen shots you will see I used a Listbox control to demonstrate the selected elements in Multiselect ComboBox. 
In the below image you will see how the search feature is working; it doesn’t affect the selected elements but will manage the display of the elements; when search text was removed all Selected elements will come back into the List.

For better understanding I am going to split the article into two parts now :
- XML or designing Part
- C# part
To define the design part I used two controls, Dropdown for selection, and one Listbox just to display selected countries.
- <ComboBox Height="30" TextBoxBase.TextChanged="ddlCountry_TextChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Name="ddlCountry" IsEditable="True" IsTextSearchEnabled="True" StaysOpenOnEdit="True" Width="165" SelectionChanged="ddlCountry_SelectionChanged" Margin="78,139,0,0">
- <ComboBox.ItemTemplate>
- <DataTemplate>
- <CheckBox Name="chkCountry" Width="220" Checked="AllCheckbocx_CheckedAndUnchecked" Unchecked="AllCheckbocx_CheckedAndUnchecked" Content="{Binding Country_Name}" IsChecked="{Binding Check_Status}" CommandParameter="{Binding Country_ID}">
- </CheckBox>
- </DataTemplate>
- </ComboBox.ItemTemplate>
- </ComboBox>
- <ListBox Name="testListbox" HorizontalAlignment="Left" Height="161" Margin="370,80,0,0" VerticalAlignment="Top" Width="100" />
- public class DDL_Country
- {
- public int Country_ID
- {
- get;
- set;
- }
- public string Country_Name
- {
- get;
- set;
- }
- public Boolean Check_Status
- {
- get;
- set;
- }
- }
- private void AddElementsInList()
- {
- // 1 element
- DDL_Country obj = new DDL_Country();
- obj.Country_ID = 10;
- obj.Country_Name = "India";
- objCountryList.Add(obj);
- obj = new DDL_Country();
- obj.Country_ID = 11;
- obj.Country_Name = "Pakistan";
- objCountryList.Add(obj);
- obj = new DDL_Country();
- obj.Country_ID = 12;
- obj.Country_Name = "America";
- objCountryList.Add(obj);
- obj = new DDL_Country();
- obj.Country_ID = 13;
- obj.Country_Name = "U.K";
- objCountryList.Add(obj);
- obj = new DDL_Country();
- obj.Country_ID = 14;
- obj.Country_Name = "Arab";
- objCountryList.Add(obj);
- }

R WardPosted Dec 22, 2021, 4:49 PM
So, this isn't exactly a solution for the selected items showing up in the combobox text, but it's a workaround at least... I just added a text box on top of the combobox covering all but the drop-down arrow, and then added code to handle when the checkbox state changes to add the selected items as a comma delimited string. private void AllCheckbox_CheckedAndUnchecked(object sender, RoutedEventArgs e) { string cusers = ""; foreach (var usr in cu) { if (usr.check_state == true) { if (cusers == "") cusers = usr.user_name; else cusers = cusers + ", " + usr.user_name; } } txtCurrentOwner.Text = cusers; }
rajeshPosted Dec 15, 2021, 12:03 PM
How to show selected item or items in combo box in same combo box above ?if anyone has solution please respond.
WDW LLCPosted Aug 29, 2019, 2:23 PM
Hey, Great article! Thanks! But I am having a problem... When I click on the whitespace, to the right of the ComboBox item text, the name of the control: "Path.To.Classes.ComboBoxClient", rather than the Country Name, ex: "India"... I have tried many things to stop this, and I cannot figure it out -- any ideas?
Ashok Kumar GangaPosted Sep 3, 2018, 5:19 AM
How to diplay selected items whenever we click that data
Khumana RamPosted Mar 7, 2017, 4:40 AM
Great post with nice explanation....
Sonu ChaudharyPosted Jun 7, 2016, 12:44 PM
good one
Kapi ShivharePosted Mar 13, 2016, 10:15 AM
nice blog...