【发布时间】:2020-05-24 10:43:24
【问题描述】:
我正在使用 MongoDB 数据库,我想在组合框中显示来自 MongoDB 的数据作为默认值。但我不知道该怎么做。
这是我的 XAML
<DataGridTextColumn Header="Kaina" Binding="{Binding full_price}" CanUserReorder="False"
IsReadOnly="True"/>
<DataGridTextColumn Header="DV" Binding="{Binding order_quantity}" CanUserReorder="False"
IsReadOnly="True"/>
<DataGridTemplateColumn Header="Stalviršio tipas">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="TableTop" DropDownClosed="TableTop_DropDownClosed" Text="fg">
<ComboBoxItem Content="A" />
<ComboBoxItem Content="B" />
<ComboBoxItem Content="C" />
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
这是我的 MongoDB 数据库文档:
_id:"B0/0045/0214-05_FP0-E202-130/70/90"
electricity_based_on:"FP0-P202"
full_price:1225.95
manufacturing_date:2020-02-13T22:00:00.000+00:00
order_code:"FP0-E202-130/70/90"
order_comment_names:"1) Stalviršis su standartiniu borteliu FP0-000-12.00 SB,
order_name:"Šaldomas stalas 2 durelių"
order_number:"B0/0045/0214-05"
order_quantity:1
unit_price:1225.95
tabletop_letter:"C"
sub3_4:""
我想将 MongoDB 中的“tabletop_letter”显示为“TableTop”组合框作为默认值。你能帮帮我吗?
【问题讨论】:
-
您的代码中的 MongoDB 查询部分完成了吗?
-
是的,我有。
//Finding all documents in "Products" collection --> var allDocuments = Classes.MdB.connectDbProducts().Find(new BsonDocument()).ToList(); //Binding MongoDB data to GridView --> Classes.MdB.GridView(productsGrid, allDocuments); //Binding data to DataGrid --> public static void GridView(DataGrid DATAGRIDAS, List<MDBProducts> cursor) { Binding bind = new Binding(); DATAGRIDAS.DataContext = cursor; DATAGRIDAS.SetBinding(ListView.ItemsSourceProperty, bind); }
标签: c# wpf mongodb combobox binding