How To Get All Selected Value in MultiSelectComboBox
Thank you for using Syncfusion products.
This reported requirement can be achieved by using SelectedItems property in MultiSelectionComboBox. Please make use below code example for your reference.
Code Snippet[C#]:
| //To get the added Visual items in MultiSelectionComboBox this.multiSelectionComboBox1.VisualItems
//To get the selected items in MultiSelectionComboBox this.multiSelectionComboBox1.SelectedItems |
We have also prepared a sample and video for your reference which can be downloaded from the below location.
Sample Location : https://www.syncfusion.com/downloads/support/forum/119991/ze/MultiSelectSelectedValue229948667
Video Location ; https://www.syncfusion.com/downloads/support/forum/119991/ze/MultiSelection1192145006
Please let us know if you need further assistance.
Regards,
Senthil
this.multiSelectionComboBox1.SelectedItems
Thanks
Thomas
|
// Custom control to display ValueMember
public class MultiSelectionComboBoxExt : MultiSelectionComboBox
//To remove the selected values if it has been unchecked
void MultiSelectionComboBoxExt_ControlRemoved(object sender, System.Windows.Forms.ControlEventArgs e)
{
for (int i = 0; i <= this.SelectedValues.Count - 1; i++)
{
if (this.SelectedValues[i].DisplayMember == e.Control.Text)
{
this.SelectedValues.RemoveAt(i);
break;
}
}
}
// To add value members of the selected values into the collection when it is checked
void MultiSelectionComboBoxExt_CheckChanged(object sender, CheckedStateEventArgs e
{
if (e.Checked)
{
this.SelectedValues.Add(new DataCollection(this.SelectedItems[this.SelectedItems.Count - 1].ToString(), e.Item.ToString()));
}
}
|
Hello,
Another way to get the selected values assuming you use a datatable with two columns pk and value (for example) would be the following:
Public Function getSelectedKeys() As List(Of String)
Dim pks As New List(Of String)()
For i As Integer = 0 To Me.SelectedItems.Count - 1
Dim dr As DataRow = CType(Me.DataSource, DataTable).Select("value = '" & SelectedItems(i) & "'").SingleOrDefault
pks.Add(dr("pk"))
Next i
Return pks
End Function
- 5 Replies
- 6 Participants
-
IN Indra
- Aug 20, 2015 03:35 PM UTC
- May 4, 2017 09:13 AM UTC