-1

I bind my ComboBox with static way.

when I set the string value which I get from item object (from service method), for example item.AssignmentType="xyz" I want to make it selectable in combobox. I tried below, but not working

<ComboBoxItem Content="abc"/>
<ComboBoxItem Content="xyz"/>
<ComboBoxItem Content="pqrs"/>

string assignmenttype = item.AssignmentType.ToString();
AssignmentTypeCombobox.SelectedIndex =
AssignmentTypeCombobox.Items.IndexOf(assignmenttype);
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Murali
  • 41
  • 5
  • [Combobox.SelectedItem](https://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selecteditem(v=vs.110).aspx) – bansi Feb 20 '17 at 06:00
  • Just try `AssignmentTypeCombobox.Text = "xyz"` – bansi Feb 20 '17 at 06:02
  • but, "Text" property not exist for UWP combobox – Murali Feb 20 '17 at 06:05
  • check [UWP Combobox binding to SelectedItem property](http://stackoverflow.com/questions/33821672/uwp-combobox-binding-to-selecteditem-property) – bansi Feb 20 '17 at 06:14

1 Answers1

0

You can bind everything senseful to a ComboBox. I would recommend some kind of collection (ObservableCollection). You need to set the DataContext to this collection and you´re ready to go. For further details check this: Bind collection to combobox

Community
  • 1
  • 1
Joshit
  • 1,238
  • 16
  • 38