//To get the added Visual items in MultiSelectionComboBox this.multiSelectionComboBox1.VisualItems
//To get the selected items in MultiSelectionComboBox this.multiSelectionComboBox1.SelectedItems |
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