填充数据网格中的组合框
我有一个使用实体框架填充来自一个 SQL 表的数据的 WPF 数据网格,是否可以使用来自不同表的数据填充同一数据网格中的组合框。
我有这个代码工作
<DataGridTemplateColumn x:Name="reasonColumn" Header="Reason" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox>
<ComboBoxItem Content="Supplier Quantity"/>
<ComboBoxItem Content="Supplier Price"/>
<ComboBoxItem Content="Supplier Numbers"/>
<ComboBoxItem Content="Supplier Codes"/>
<ComboBoxItem Content="Branch Quantity"/>
<ComboBoxItem Content="Branch Numbers"/>
<ComboBoxItem Content="Branch Codes"/>
<ComboBoxItem Content="IM Numbers"/>
<ComboBoxItem Content="Pop Prices"/>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
但我希望它是动态填充的。
谢谢。
I have a WPF Datagrid populated with data from one SQL table using Entity Framework, is it possible to populate a combobox in the same Datagrid using data from a different table.
I have this code working
<DataGridTemplateColumn x:Name="reasonColumn" Header="Reason" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox>
<ComboBoxItem Content="Supplier Quantity"/>
<ComboBoxItem Content="Supplier Price"/>
<ComboBoxItem Content="Supplier Numbers"/>
<ComboBoxItem Content="Supplier Codes"/>
<ComboBoxItem Content="Branch Quantity"/>
<ComboBoxItem Content="Branch Numbers"/>
<ComboBoxItem Content="Branch Codes"/>
<ComboBoxItem Content="IM Numbers"/>
<ComboBoxItem Content="Pop Prices"/>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
But I would prefer it to be dynamically populated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,只需将您的
ComboBox.ItemsSource
绑定到您的集合所在的位置例如,这将绑定来自 DataGrid 的 DataContext 的集合:
作为另一个示例,这将绑定到包含您的集合的静态类
Yes, simply bind your
ComboBox.ItemsSource
to wherever your collection isFor example, this will bind a collection from your DataGrid's DataContext:
As another example, this will bind to a static class containing your collection