wpf-Datagrid每行combobox设置不同值

C# 代码

public partial class MainWindow : Window
    {
        List students;
        public MainWindow()
        {
            InitializeComponent();
            students = new List();
            students.Add(new Student() { Id = 1, SelectedOption = 0, options = new List<select>() { new select() { selectId = 1, TeamName = "Name1" }, new select() { selectId = 2, TeamName = "Name2" } } });
            students.Add(new Student() { Id = 2, SelectedOption = 0, options = new List<select>() { new select() { selectId = 1, TeamName = "Name3" }, new select() { selectId = 2, TeamName = "Name4" } } });
            students.Add(new Student() { Id = 3, SelectedOption = 0, options = new List<select>() { new select() { selectId = 1, TeamName = "Name5" }, new select() { selectId = 2, TeamName = "Name6" } } });

            dg1.ItemsSource = students;
        }
        public class Student
        {
            public int Id { get; set; }
            public int SelectedOption { get; set; }
            public List<select> options { get; set; }
            public Student()
            {
                options = new List<select>();
            }
        }
        public class Option
        {
            public List<string> myoption { get; set; }

            public Option()
            {
                myoption = new List<string>();
            }
        }
        public class select
        {
            public int selectId { get; set; }
            public string TeamName { get; set; }
        }
    }

xaml:

  "dg1" AutoGenerateColumns="False">
            
                "Id" Binding="{Binding Id}" />
                "Options" SelectedValueBinding="{Binding SelectedOption}" SelectedValuePath="selectId" DisplayMemberPath="TeamName">
                    
                        
                    
                    
                        
                    
                
            
        
    

wpf-Datagrid每行combobox设置不同值_第1张图片

 

SelectedOption属性是默认Combobox选择第几行。


你可能感兴趣的:(wpf-Datagrid每行combobox设置不同值)