0

I have CheckListBox(Multi Select ListBox).

My CheckListBox has,

MyMultiListComboBox.DataSource = context.GetValues();
MyMultiListComboBox.DisplayMember = "Name";
MyMultiListComboBox.ValueMember = "Id";

I try to get selected multi values like below,

var Values = MyMultiListComboBox.SelectedValue;

However i get only first selected value.How can i get all selected values in WinForms c# ?

Any help will be appreciated .

Thanks.

3
  • What is the data type that context.GetValues() returns? Commented Nov 27, 2013 at 14:34
  • I list data of my customers Commented Nov 27, 2013 at 14:34
  • please be specific, List<Customer> or something else? Commented Nov 27, 2013 at 14:34

2 Answers 2

2

You can try this code:

var values = MyMultiListComboBox.SelectedItems.Cast<Customer>()
                                .Select(x=>x.Id).ToList();
Sign up to request clarification or add additional context in comments.

Comments

0

Depending on the data Type of the list context.GetValues() is returning you can use SelectedItems on the CheckListBox and then just ConvertAll to the type that is required for your list.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.