在c#,wpf中,如何将存储在数据库中的值设置/分配给sqlite数据库中基于datagrid的复选框

本文关键字:数据库 sqlite 分配 复选框 datagrid 设置 存储 wpf | 更新日期: 2023-09-27 18:29:11

在wpf中,我的sqlite数据库列中有一条记录的值为true,但它不会显示为datagrid列中的标记checked。有人能帮忙吗?xaml代码:

    <DataGrid x:Name="DG_VendorPur" AutoGenerateColumns="False" ItemsSource="{Binding VendorProducts}" Grid.Row="7" Grid.RowSpan="4" FontFamily="Franklin Gothic Medium" FontSize="18" Background="#FFEBDCEB" AlternatingRowBackground="#FFDAE7F5" SelectionMode="Single" ColumnWidth="*" Grid.Column="5" Grid.ColumnSpan="6" SelectedCellsChanged="DG_VendorPur_SelectedCellsChanged">
                    <DataGrid.Columns>
                        <DataGridCheckBoxColumn x:Name="DG_V_IsDefault" Header=" Preferred "    MinWidth="50" Width="*" Binding="{Binding Path=VP_isVendorActive, Mode=TwoWay}" SortDirection="Ascending" IsThreeState="True" />
                        <DataGridTextColumn     x:Name="DG_Vname"       Header=" Vendor Name "  MinWidth="50" Width="*" Binding="{Binding Path=VP_Vname}"       FontFamily="Calibri" />
                        <DataGridTextColumn     x:Name="DG_VItemNo"     Header=" Vendor SKU# "  MinWidth="50" Width="*" Binding="{Binding Path=VP_VendorSKU}"   FontFamily="Calibri"/>
                        <DataGridTextColumn     x:Name="DG_VCaseCost"   Header=" Case Cost "    MinWidth="50" Width="*" Binding="{Binding Path=VP_SKUcaseCost}" FontFamily="Calibri"/>
                        <DataGridTextColumn     x:Name="DG_VQtyPerCase" Header=" Qty/Case "     MinWidth="50" Width="*" Binding="{Binding Path=VP_QtyInCase}"   FontFamily="Calibri"/>
                    </DataGrid.Columns>
                </DataGrid>

xaml.cs:

    sqliteCon.Open();
                string Product = TB_PscanID.Text;
                cmd.CommandText = "Select VP_Vname,VP_VendorSKU,VP_SKUcaseCost,VP_QtyInCase from VendorProducts where VP_ProductID= @WORD";
                cmd.Parameters.AddWithValue("@word", Product);
                cmd.Prepare();
                cmd.ExecuteNonQuery();
                SQLiteDataAdapter SDAdap = new SQLiteDataAdapter(cmd);
                DataTable DT = new DataTable("VendorProducts");
                SDAdap.Fill(DT);
                DG_VendorPur.ItemsSource = DT.DefaultView;
                DataRecord = DG_VendorPur.Items.Count;
                SDAdap.Update(DT);
                sqliteCon.Close();

在c#,wpf中,如何将存储在数据库中的值设置/分配给sqlite数据库中基于datagrid的复选框

问题在于您的查询:

SELECT VP_isVendorActive, /* You're missing this column */
       VP_Vname,
       VP_VendorSKU,
       VP_SKUcaseCost,
       VP_QtyInCase
FROM VendorProducts WHERE VP_ProductID= @WORD