datagrid 相关问题

一个图形用户界面元素,用于显示数据的表格视图。

Amazon Redshift、Datagrid 找到锁并杀死

我正在尝试查找锁定sql查询,并且我使用了这段代码, 但是当我想取消查询列表时却不起作用。 你能帮忙吗? 选择 * 从 stv_locks;

回答 1 投票 0

WPF c# datagrid 设置单独行高

我对 WPF 和 C# 还很陌生。 我正在尝试创建一个数据网格,我可以在其中以编程方式设置各行的高度。 似乎可以一起更改所有行的高度...

回答 3 投票 0

如何在 DataGrid WinUI 3 中创建“可搜索/过滤”组合框

就官方文档而言,一切都是无望的。我已经检查了整个网络,询问了 chatGpt 但没有帮助。对于 WinUI 3 的 DataGrid 中的每个单元格,我需要这样的东西。 我尝试过使用

回答 1 投票 0

我有一个 C# WinUI 3 桌面应用程序 (VS 2019) - 在数据网格单元格中右对齐文本

使用数据网格。 我想右对齐某些列。 我下面的方法试过了,不行。 有谁知道正确的方法吗? 多谢。 使用数据网格。 我想右对齐某些列。 我下面的方法试过了,不行。 有谁知道正确的方法吗? 非常感谢。 <Grid Grid.Row="2" HorizontalAlignment="Center"> <controls:DataGrid x:Name="Results_DataGrid" AutoGenerateColumns="False" CanUserSortColumns="False" AreRowDetailsFrozen="True" BorderBrush="#005986" BorderThickness="2 2 2 2" Margin="3 10 3 5" PointerReleased="Results_DataGrid_PointerReleased"> <controls:DataGrid.Columns> <controls:DataGridTextColumn Header="Jan" Width="SizeToHeader" Binding="{Binding Jan}" FontSize="11" Foreground="Black" > **<controls:DataGridTextColumn.ElementStyle> <Style TargetType="controls:DataGridCell"> <Setter Property="HorizontalAlignment" Value="Right"/> </Style> </controls:DataGridTextColumn.ElementStyle>** </controls:DataGridTextColumn> </controls:DataGrid.Columns> </controls:DataGrid> ElementStyle 中的 DataGridTextColumn 目标为 TextBlock。 <controls:DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="HorizontalTextAlignment" Value="Right" /> </Style> </controls:DataGridTextColumn.ElementStyle> 我也可以使用 CellStyle 来实现此目的。 <controls:DataGridTextColumn.CellStyle> <Style TargetType="controls:DataGridCell"> <Setter Property="HorizontalContentAlignment" Value="Right" /> </Style> </controls:DataGridTextColumn.CellStyle>

回答 1 投票 0

在 WinUI 3 DataGrid 中禁用行选择

我一直在努力禁用数据网格行上的悬停、鼠标悬停和行选择。我过去曾在 Wpf 应用程序中使用过以下代码,它运行得很好。然而,我是……

回答 1 投票 0

WinUI 3 DataGrid 列与 x:Bind

是否有 MVVM 方式(使用 ViewModel)在 XAML 中为 DataGrid 列(DataGridTextColumn 等)使用 x:bind? 我见过的所有代码都使用 Binding 而不是 x:Bind。

回答 1 投票 0

WinUI 3 中的 DataTable 和 DataColumn 在哪里?

我想在WinUI 3中使用DataGrid,我注意到WinUI3库和Windows Community Toolkit库有不同的DataGrid表格控件。 我找不到 DataTable 所在的位置...

回答 1 投票 0

WinUI 3 DataGrid:更改标题字体大小

我正在 WinUI 3 中使用 Windows Community Toolkit 中的 DataGrid。可用的信息非常少,我正在努力解决它。如何更改标题的字体大小?阿尔...

回答 1 投票 0

DataGrid 列宽不会自动更新

当 Change 的值更新时,其列不会更新为 fi...

回答 6 投票 0

如何根据 FluentDataGrid 的值设置各个单元格的样式?

我有一个 Blazor Fluent-UI FluentDataGrid,我想实现热图效果。尝试避免编写任何 JavaScript - 有什么方法可以将样式应用于单个单元格以实现......

回答 1 投票 0

数据网格宽度 WinUI 3

我是WinUI 3的新手,我正在做一个数据网格来显示产品列表,当总宽度不是完整的数据网格宽度而是显示水平时,我想让数据网格列填充数据网格。 .

回答 1 投票 0

根据值更改 DataGrid 单元格颜色

我有一个 WPF 数据网格,我想要根据值使用不同的单元格颜色。我的 xaml 上有以下代码 样式 TargetType="DataGridCell" 但不是选择一个单元格而是选择...

回答 10 投票 0

具有验证错误样式的 WPF Datagrid 单元格

当出现验证错误时,我尝试更改 DataGridCell(在 WPF 工具包 DataGrid 中)的默认样式。 默认为红色边框。 我怎样才能放置自己的模板? 谢谢。

回答 4 投票 0

MUI 数据网格中的表和过滤器列不同

在“学生详细信息”列中,我想堆叠三列中的数据值:姓名、专业和年份。是否可以做到这一点,同时仍然保持按单个列过滤的能力......

回答 1 投票 0

根据表格(DataGrid)的选定行设置按钮(ICommand)的操作

我有一个窗口 WPF 和 2 个表 DataGrid。 DataContext 绑定到类 PersonalTaskClassPickerViewModel.cs。 PersonalTaskClassPicker.xaml 我有一个窗口 WPF 和 2 个表 DataGrid。 DataContext 绑定到类 PersonalTaskClassPickerViewModel.cs。 PersonalTaskClassPicker.xaml <Window x:Class="WpfAppTaskPlanner.PersonalTaskClassPicker" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:viewModels="clr-namespace:WpfAppTaskPlanner.ViewModels" xmlns:views="clr-namespace:WpfAppTaskPlanner" xmlns:taskClassDirectory="clr-namespace:Library.TaskClassDirectory;assembly=Library" mc:Ignorable="d" Title="MainWindow" Height="850" Width="1500" d:DataContext="{d:DesignInstance viewModels:PersonalTaskClassPickerViewModel}"> <Window.Resources> <viewModels:OutputValueConverter x:Key="OutputValueConverter"></viewModels:OutputValueConverter> <DataTemplate x:Key="CustomDataGridHeaderTemplate"> <views:CustomDataGridHeader></views:CustomDataGridHeader> </DataTemplate> </Window.Resources> <DockPanel LastChildFill="True"> <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" DockPanel.Dock="Bottom"> <!--Other buttons--> <Button HorizontalAlignment="Center" VerticalAlignment="Center" Content="Удалить задачу" Width="100" Height="40" Margin="15 5" Command="{Binding RemoveTaskClassCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"/> </StackPanel> <StackPanel DockPanel.Dock="Top"> <TextBlock Text="Связанные задачи" Margin="0 5"></TextBlock> <DataGrid x:Name="DataGridRelatedPersonalTaskClass" DockPanel.Dock="Top" ItemsSource="{Binding SelectedTaskPerformerClass.PersonalTaskClassLists.RelatedList, FallbackValue='SelectedTaskPerformerClass не не выбран'}" SelectedItem="{Binding SelectedTaskClass, Mode=TwoWay}"> <DataGrid.Columns> <DataGridTextColumn Header="Участок" HeaderTemplate="{StaticResource CustomDataGridHeaderTemplate}" Binding="{Binding BrigadeIndex}" IsReadOnly="True"/> <!--Other DataGridTextColumns--> </DataGrid.Columns> </DataGrid> <TextBlock Text="Удаленные задачи" Margin="0 5"></TextBlock> <DataGrid x:Name="DataGridDeletedPersonalTaskClass" DockPanel.Dock="Bottom" ItemsSource="{Binding SelectedTaskPerformerClass.PersonalTaskClassLists.DeletedList, FallbackValue='SelectedTaskPerformerClass не не выбран'}" SelectedItem="{Binding SelectedTaskClass, Mode=TwoWay}"> <DataGrid.Columns> <DataGridTextColumn Header="Участок" HeaderTemplate="{StaticResource CustomDataGridHeaderTemplate}" Binding="{Binding BrigadeIndex}" IsReadOnly="True"/> <!--Other DataGridTextColumns--> </DataGrid.Columns> </DataGrid> </StackPanel> </DockPanel> </Window> PersonalTaskClassPicker.xaml.cs public partial class PersonalTaskClassPicker { public PersonalTaskClassPicker(ref TaskPerformerClass selectedTaskPerformerClass) { InitializeComponent(); DataContext = new PersonalTaskClassPickerViewModel(ref selectedTaskPerformerClass); } } PersonalTaskClassPickerViewModel.cs public class PersonalTaskClassPickerViewModel: BaseViewModel { public PersonalTaskClassPickerViewModel(ref TaskPerformerClass selectedTaskPerformerClass) { RemoveTaskClassCommand = new RelayCommand(RemoveTaskClass, CanRemoveTaskClass); // Other ICommand's } } BaseViewModel.cs public class BaseViewModel : BaseNotifyPropertyChanged { private TaskClass? _selectedTaskClass; public TaskClass? SelectedTaskClass { get => _selectedTaskClass; set { if (Equals(value, _selectedTaskClass)) { return; } if (SetField(ref _selectedTaskClass, value)) { CallRaiseCanExecuteChanged(RemoveTaskClassCommand); } } } private TaskPerformerClass? _selectedTaskPerformerClass; public TaskPerformerClass? SelectedTaskPerformerClass { get => _selectedTaskPerformerClass; set { if (_selectedTaskPerformerClass != value) { _selectedTaskPerformerClass = value; OnPropertyChanged(); } } } public ICommand? RemoveTaskClassCommand { get; protected init; } public static void CallRaiseCanExecuteChanged(ICommand? command) { switch (command) { case AsyncRelayCommandWithParameter getToWorkCommand: getToWorkCommand.RaiseCanExecuteChanged(); break; case RelayCommand getToWorkCommand: getToWorkCommand.RaiseCanExecuteChanged(); break; } } protected bool CanRemoveTaskClass(object parameter) { if (parameter is not PersonalTaskClassPicker { DataContext: PersonalTaskClassPickerViewModel personalTaskClassPickerViewModel }) { return false; } if (personalTaskClassPickerViewModel.SelectedTaskPerformerClass is null) { MessageBox.Show("personalTaskClassPickerViewModel.SelectedTaskPerformerClass is null"); } else { var taskPerformer = personalTaskClassPickerViewModel.SelectedTaskPerformerClass; if (SelectedTaskClass is not null && taskPerformer.PersonalTaskClassLists.RelatedList is not null && taskPerformer.PersonalTaskClassLists.RelatedList.Contains(SelectedTaskClass)) { return true; } } return false; } protected void RemoveTaskClass(object parameter) { if (parameter is not PersonalTaskClassPicker { DataContext: PersonalTaskClassPickerViewModel personalTaskClassPickerViewModel }) { return; } if (personalTaskClassPickerViewModel.SelectedTaskPerformerClass is null) { MessageBox.Show("personalTaskClassPickerViewModel.SelectedTaskPerformerClass is null"); } else { var personalTaskClassListsOfTaskPerformerClass = personalTaskClassPickerViewModel.SelectedTaskPerformerClass.PersonalTaskClassLists; var selectedTaskClass = SelectedTaskClass; if (selectedTaskClass is not null && personalTaskClassListsOfTaskPerformerClass.RelatedList is not null && personalTaskClassListsOfTaskPerformerClass.RelatedList.Contains(selectedTaskClass)) { personalTaskClassListsOfTaskPerformerClass.RelatedList.Remove(selectedTaskClass); personalTaskClassListsOfTaskPerformerClass.DeletedList ??= new ObservableCollection<TaskClass>(); personalTaskClassListsOfTaskPerformerClass.DeletedList.Add(selectedTaskClass); personalTaskClassListsOfTaskPerformerClass.OnPropertyChanged( nameof(personalTaskClassListsOfTaskPerformerClass.RelatedList) ); personalTaskClassListsOfTaskPerformerClass.OnPropertyChanged( nameof(personalTaskClassListsOfTaskPerformerClass.DeletedList) ); CallRaiseCanExecuteChanged(RemoveTaskClassCommand); } } } } BaseNotifyPropertyChanged.cs public class BaseNotifyPropertyChanged : INotifyPropertyChanged { public event PropertyChangedEventHandler? PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } protected bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null) { if (EqualityComparer<T>.Default.Equals(field, value)) { return false; } field = value; OnPropertyChanged(propertyName); return true; } protected class RelayCommand : ICommand { private readonly Action<object> _execute; private readonly Predicate<object>? _canExecute; public RelayCommand(Action<object> execute, Predicate<object>? canExecute = null) { _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } public bool CanExecute(object? parameter) => _canExecute == null || _canExecute(parameter ?? "<N/A>"); public void Execute(object? parameter) { _execute(parameter ?? "<N/A>"); } public event EventHandler? CanExecuteChanged { add => CommandManager.RequerySuggested += value; remove => CommandManager.RequerySuggested -= value; } public void RaiseCanExecuteChanged() { CommandManager.InvalidateRequerySuggested(); } } //Other AsyncRelayCommand's } 从主 WPF 窗口调用 WPF 窗口,如下所示: public class MainViewModel : BaseViewModel { //Other code private static void OnEditPersonalTaskClassList(object parameter) { if (parameter is not TaskPerformerClass selectedTaskPerformerClass) { return; } var personalTaskClassEditor = new PersonalTaskClassPicker(ref selectedTaskPerformerClass); if (personalTaskClassEditor.ShowDialog() == true) { //Other commands } else { MessageBox.Show("DataContext закрытого окна не является типом TaskPerformerClass"); } } } TaskPerformerClass.cs namespace Library.TaskPerformerDirectory; public sealed class TaskPerformerClass : INotifyPropertyChanged { //Other private values private PersonalTaskClassCollection _personalTaskClassLists = null!; private TaskPerformerClass() { } public TaskPerformerClass( FullNameOfThePerson fullName, WorkDay workDay, CalendarYearOfTaskPerformer calendarYearOfTaskPerformer, int bitrixEmployeeIndex, List<Department>? bitrixEmployeeDepartmentList = null, TaskClass? actualTask = null ) { //Other initializations of properties PersonalTaskClassLists = new PersonalTaskClassCollection(this); } //Other property public PersonalTaskClassCollection PersonalTaskClassLists { get => _personalTaskClassLists; set { if (Equals(value, _personalTaskClassLists)) { return; } _personalTaskClassLists = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler? PropertyChanged; public void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null) { if (EqualityComparer<T>.Default.Equals(field, value)) { return false; } field = value; OnPropertyChanged(propertyName); return true; } } PersonalTaskClassCollection.cs public sealed class PersonalTaskClassCollection : INotifyPropertyChanged { private int _id; private int _taskPerformerClassId; private TaskPerformerClass _taskPerformerClass = null!; private ObservableCollection<TaskClass>? _completedList; private ObservableCollection<TaskClass>? _deletedList; private ObservableCollection<TaskClass>? _relatedList; private PersonalTaskClassCollection() { } public PersonalTaskClassCollection(TaskPerformerClass taskPerformerClass) => TaskPerformerClass = taskPerformerClass; public int Id { get => _id; set { if (value == _id) { return; } _id = value; OnPropertyChanged(); } } public int TaskPerformerClassId { get => _taskPerformerClassId; set { if (value == _taskPerformerClassId) { return; } _taskPerformerClassId = value; OnPropertyChanged(); } } public TaskPerformerClass TaskPerformerClass { get => _taskPerformerClass; set { if (Equals(value, _taskPerformerClass)) { return; } _taskPerformerClass = value; OnPropertyChanged(); } } public ObservableCollection<TaskClass>? RelatedList { get => _relatedList; set { if (Equals(value, _relatedList)) { return; } _relatedList = value; OnPropertyChanged(); } } public ObservableCollection<TaskClass>? DeletedList { get => _deletedList; set { if (Equals(value, _deletedList)) { return; } _deletedList = value; OnPropertyChanged(); } } public ObservableCollection<TaskClass>? CompletedList { get => _completedList; set { if (Equals(value, _completedList)) { return; } _completedList = value; OnPropertyChanged(); } } public event PropertyChangedEventHandler? PropertyChanged; public void OnPropertyChanged([CallerMemberName] string? propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } private bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null) { if (EqualityComparer<T>.Default.Equals(field, value)) { return false; } field = value; OnPropertyChanged(propertyName); return true; } } 我认为描述“TaskClass.cs”类没有任何意义。它只是一个包含任务属性的类。 在“DataGridRelatedPersonalTaskClass”和“DataGridDeletedPersonalTaskClass”这两个表中随机选择一行后,“RemoveTaskClassCommand”按钮将永远无法更改“set”属性“SelectedTaskClass”的值。因此,如果单击它,“DataGridRelatedPersonalTaskClass”中下一个突出显示的任务将被删除。 随着时间的推移,我意识到,如果我突出显示表中的每个问题,那么每个“DataGrid”的“SelectedItem”属性将继续处于活动状态,但我的“SelectedTaskClass”属性并不总是更新。尽管“IsMouseOver”属性始终正确显示我最后突出显示的表中的行。 当选择“DataGridRelatedPersonalTaskClass”表中的一行时,我想正确配置“RemoveTaskClassCommand”按钮的活动。怎么办? 首先,有一个重要的说明。您传递 Window 命令参数 CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=Window}}"。 由于此命令是一个 ViewModel 实体,并且根据 MVVM 规则,禁止将任何 UI 元素传递给 ViewModel,那么您的实现实际上完全破坏了 MVVM 合规性。 关于你问题的本质。 您的任务的可能实现选项之一的最简化示例。 namespace Core2024.SO.Zhan.question79147702 { public class SomeTextItem { private string _title = string.Empty; private string _text = string.Empty; private string _description = string.Empty; public string Title { get => _title; set => _title = value ?? string.Empty; } public string Text { get => _text; set => _text = value ?? string.Empty; } public string Description { get => _description; set => _description = value ?? string.Empty; } } } using Simplified; // This is the space with my implementation of INotifyPropertyChanged and ICommand interfaces. You can use your own implementations instead. using System.Collections.ObjectModel; namespace Core2024.SO.Zhan.question79147702 { public class SomeTextViewModel { private const string data = "After randomly selecting a row in each of the 2 tables \"DataGridRelatedPersonalTaskClass\" and \"DataGridDeletedPersonalTaskClass\", the \"RemoveTaskClassCommand\" button will never be able to change the value of the \"set\" property \"SelectedTaskClass\". Thus, if you click on it, the next highlighted task in the \"DataGridRelatedPersonalTaskClass\" will be deleted. Over time, I realized that if I highlighted each question in the tables, then the \"SelectedItem\" properties of each \"DataGrid\" continue to be active, but my \"SelectedTaskClass\" property is not always updated.Although the \"IsMouseOver\" property always correctly displays the row in which table I highlighted last."; private static IEnumerable<SomeTextItem> GetItems() { string[] split = data.Split(); for (int i = 2; i < split.Length; i+=3) { yield return new SomeTextItem() { Title = split[i-2], Text = split[i-1], Description = split[i] }; } } public SomeTextViewModel() { TextItems = new ObservableCollection<SomeTextItem>(GetItems()); RemoveTextItem = new RelayCommand<SomeTextItem> ( item => TextItems.Remove(item), item => TextItems.Contains(item) ); } public ObservableCollection<SomeTextItem> TextItems { get; } public RelayCommand RemoveTextItem { get; } } } <Window x:Class="Core2024.SO.Zhan.question79147702.SomeTextWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Core2024.SO.Zhan.question79147702" mc:Ignorable="d" Title="SomeTextWindow" Height="450" Width="800" DataContext="{DynamicResource vm}"> <Window.Resources> <local:SomeTextViewModel x:Key="vm"/> </Window.Resources> <Grid> <DataGrid ItemsSource="{Binding TextItems}"> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate DataType="{x:Type local:SomeTextItem}"> <Button Content="Remove Item" CommandParameter="{Binding Mode=OneWay}" Command="{Binding RemoveTextItem, Mode=OneWay, Source={StaticResource vm}}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> </Grid> </Window>

回答 1 投票 0

在 DataGrid 内滚动父容器

我有这个自定义数据网格。我想要实现的是,当用户将鼠标放在 DataGrid 内部(没有最大高度)时,它应该允许滚动整个父组件...

回答 1 投票 0

如何在scrollviewer中设置滚动条的粗细

如何控制作为 DataGrid 控件一部分显示在 / 中的水平或垂直滚动条的厚度? 我希望它们显示得比实际情况“更厚”

回答 1 投票 0

Winui3:有没有办法转换用作 ItemsSource 的集合的成员

我正在尝试完成与这个问题所要求的相同的任务,特别是这个答案,但我正在winui3中工作(特别是我正在使用CommunityToolkit DataGrid),并且似乎没有任何东西

回答 1 投票 0

ASP.NET 端 Datagrid 中数据的动态过滤器

我有一个带有 Ajax 的 ASP.NET 页面和一个数据网格(数据表)。数据网格的列中有搜索字段。 对于普通搜索字段,来自数据源的数据过滤如下: 我的数据...

回答 1 投票 0

Material-ui Datagrid 不稳定保持刷新

下面是我用来从 api 获取数据并将其绑定到 materi ui 数据网格的代码。我使用的版本是“@mui/x-data-grid”:“^7.18.0”,

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.