0

With the following code the combobox cbAdditionalFields is not holding the selected value in SelectedItem property. How to get the selected item property of the combobox? and on selection changed not focus

var userFields = recordType.UserFields.Where(u => u.Format == UserFieldFormats.String); cbAdditionalFields.DataSource = userFields.ToList(); cbAdditionalFields.DisplayMember = "Name"; 
1
  • Set DisplayMember before DataSource Commented Feb 24, 2017 at 1:54

2 Answers 2

2

This might do the trick for you

private void cbAdditionalFields_SelectionChanged(object sender, SelectionChangedEventArgs e) { // ... Get the ComboBox. var comboBox = sender as ComboBox; //string value = comboBox.SelectedItem as string; UserField value = comboBox.SelectedItem as UserField; Console.WriteLine(value.Name); } 

Now value contains the currently selected item in the ComboBox.

Sign up to request clarification or add additional context in comments.

1 Comment

SelectedItem is not having the "Name" property, it is showing as an object of type UserField
0

you can solve this issue by setting the selected index or selected value property of the ComboBox. cb.selectedIndex = 0;

1 Comment

I get an error "Cannot set the SelectedValue in a ListControl with an empty ValueMember."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.