填充数据网格中的组合框

发布于 2024-12-14 21:12:41 字数 1247 浏览 6 评论 0原文

我有一个使用实体框架填充来自一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱影子 2024-12-21 21:12:41

是的,只需将您的 ComboBox.ItemsSource 绑定到您的集合所在的位置

例如,这将绑定来自 DataGrid 的 DataContext 的集合:

<ComboBox ItemsSource="{Binding DataContext.MyComboBoxList, 
          RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />

作为另一个示例,这将绑定到包含您的集合的静态类

<ComboBox ItemsSource="{Binding 
          Source={x:Static local:MyStaticClass.MyComboBoxList}" />

Yes, simply bind your ComboBox.ItemsSource to wherever your collection is

For example, this will bind a collection from your DataGrid's DataContext:

<ComboBox ItemsSource="{Binding DataContext.MyComboBoxList, 
          RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />

As another example, this will bind to a static class containing your collection

<ComboBox ItemsSource="{Binding 
          Source={x:Static local:MyStaticClass.MyComboBoxList}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文