Combobox Index RRS feed

  • General discussion

  • Hello guys,

    I'm loading a combobox using a return of a WCF Service. So, I can add a different items in this comboBox. I'm linking the Name and Id in this combobox.

    In other moment I need to change the text using the Id (that is behind).


    combobox.SelectedIndex = (where(Id) == e.Result);

    It is difficult to explain. But if is necessary I can try again.

    Friday, September 28, 2012 12:34 PM

All replies

  • You may need to bind a collection of custom class to the combobox.


    public class MyComboItem
    public int Id { get; set; }
    public string Name { get; set; }
    // Initialte the Collection as follows
    var collection = new ObservableCollection<MyComboItem>();
    collection.Add(new MyComboItem{ Id=1, Name="Test Name 1"});
    collection.Add(new MyComboItem{ Id=2, Name="Test Name 2"});
    // Bind the combobox as follows
    combo.ItemsSource = collection;

    In the XAML use the following code

    <ComboBox x:Name="combo">
                    	<TextBlock Text="{Binding Path=Name}"/>

    Tuesday, October 2, 2012 3:22 AM