WPF DataGrid: DataGridComboxBox ItemsSource Binding to a Collection of Collections

后端 未结 5 2233
北海茫月
北海茫月 2020-12-01 03:58

Situation:

I\'ve created a DataGrid in XAML and the ItemsSource is binded to an ObservableCollection of a certain class that contains properties. Then in C#, I cre

5条回答
  •  鱼传尺愫
    2020-12-01 04:48

    Firstly, this should be easy... secondly, why are you building (and binding) columns in C#? Eek.

    XAML (I'm using a regular grid because I'm lazy):

    
        
            
    
                
    
                    
    
                    
                        
                            
                                
                            
                        
                    
    
                
    
            
        
    
    

    C#:

    void Window1_Loaded(object sender, RoutedEventArgs e)
    {
        var dahList = new List();
    
        dahList.Add(new StatsOperation
        {
            Operation = "Op A",
            Choices = new string[] { "One", "Two", "Three" },
        });
    
        dahList.Add(new StatsOperation
        {
            Operation = "Op B",
            Choices = new string[] { "4", "5", "6" },
        });
    
        this.MyListView.ItemsSource = dahList;
    }
    

    The Results:

    WPF grid with dynamic combo box choices http://www.singingeels.com/Articles/Articles/UserImage.aspx?ImageID=b1e3f880-c278-4d2b-bcc2-8ad390591200

提交回复
热议问题