如何在c#wpf数据网格中对Radiobox列进行排序,因为我希望选中的(首选)数据记录显示在顶部

本文关键字:数据 我希望 因为 顶部 显示 记录 首选 网格 数据网 c#wpf Radiobox | 更新日期: 2023-09-27 18:29:35

因为WPF没有对Radiobox列进行排序。有人能帮忙吗?这是我显示记录的代码。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>
                        <DataGridTemplateColumn Header="Preferred" Width="90">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <RadioButton x:Name="DG_isPreferred" HorizontalAlignment="Center" GroupName="Preferred" IsChecked="{Binding Path=VP_isVendorActive, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" MaxWidth="25" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                        <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="100" Binding="{Binding Path=VP_SKUcaseCost}" FontFamily="Calibri"/>
                        <DataGridTextColumn     x:Name="DG_VQtyPerCase" Header=" Qty/Case "     MinWidth="50" Width="100" 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,VP_isVendorActive 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;
                sqliteCon.Close();

如何在c#wpf数据网格中对Radiobox列进行排序,因为我希望选中的(首选)数据记录显示在顶部

已解决:我在Select命令中对Sqlite数据库进行排序:"Select VP_Vname,VP_VendorSKU,VP_SKUcaseCost,VP_QtyInCase,VP_isVendorActive from VendorProducts where VP_ProductID=@WORD ORDER BY VP_isVendorActive DESC";

相关文章: