Here's a function to populate a combobox with SaveState.SaveName values. As you can see I'm not using ItemsSource I'm looking for a better way to do this function.
public void RestoreState(List<SaveState> names)
{
    foreach (SaveState st in names)
    {
        Label l = new Label();
        l.Content = st.SaveName;
        this.comboBox1.Items.Add(l); 
    }
}
I tried this:
this.comboBox1.ItemsSource = names; 
开发者_C百科But the combobox was populated with my datatype. Can I use the ItemsSource in such a way that it populates the combobox with the data member "SaveName"?
this.comboBox1.ItemSource = names.Select(o=>o.SaveName)
Is this what you want?
Another way to do it:
this.comboBox1.DataSource = names;
this.comboBox1.DisplayMember = "SaveName";
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论