日期:2014-05-17 浏览次数:21086 次
<Grid>
<DataGrid Name="datagrid1" Margin="148,68,0,0" AutoGenerateColumns="False" Height="131" Width="244">
<DataGrid.Columns>
<DataGridTextColumn Header="科室" Width="105" Binding="{Binding Path=Name}" />
<DataGridTextColumn Header="人数" Binding="{Binding Path=Number}" />
<DataGridComboBoxColumn ItemsSource="{Binding Path=People}" SelectedItemBinding="{Binding Path=K_科长}"
Header="科长" />
</DataGrid.Columns>
</DataGrid>
</Grid>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
ObservableCollection<Company> obc = new ObservableCollection<Company>();
obc.Add(new Company() { Name = "人教科",Number=2,K_科长="熊俊",People=new List<string>(){"熊俊","王晓"}});
obc.Add(new Company() { Name = "广告科", Number = 2, K_科长 = "汤姆", People = new List<string>() { "汤姆", "杰克" } });
obc.Add(new Company() { Name = "财会科", Number = 2, K_科长 = "李莹", People = new List<string>() { "李莹", "张三" } });
obc.Add(new Company() { Name = "人教科", Number = 4, K_科长 = "李刚", People = new List<string>() { "李刚", "王二","牛熊","刘麻子" } });
datagrid1.ItemsSource = obc;
}
}
class Company
{
public string Name { get; set; }
public int Number { get; set; }