我在C# WPF项目和DataGrid的Itemsource
填充代码中有一个DataGrid
。我为其中一列设置了默认值,但在双击该列之前,它不会显示该值!此外,在CellEndEdit
中,我测试更改下一列的值,但在双击它之前,它无法真实的显示该值(单击以编辑它)
更改数据后我尝试了哪些操作:
DGR_SUB_INVOLST.Items.Refresh();
DGR_SUB_INVOLST.BeginEdit();
DGR_SUB_INVOLST.CommitEdit();
DGR_SUB_INVOLST.InvalidateVisual();
DGR_SUB_INVOLST.UpdateLayout();
我该怎么做:
XAML文件:
<DataGrid x:Name="DGR_SUB_INVOLST"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
ScrollViewer.CanContentScroll="False"
ItemsSource="{Binding ALL_DATA_INVO, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
AutoGenerateColumns="False" FlowDirection="RightToLeft" CellEditEnding="DGR_SUB_INVOLST_CellEditEnding" SelectionUnit="Cell">
<DataGrid.Columns >
<DataGridTextColumn Header="ردیف" x:Name="RADIF_COL" Binding="{Binding RADIF}" MinWidth="40" Visibility="Hidden"/>
<DataGridComboBoxColumn x:Name="ANBAR_COL" Width="80" Header=" انبار " SelectedValueBinding="{Binding CODE,UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="NAMES" SelectedValuePath="CODE">
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="IsEditable" Value="True"/>
<Setter Property="ItemsPanel" Value="{StaticResource VSP}"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
<Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
<Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
<DataGridTextColumn Header="نام کالا" x:Name="NAME_COL" Binding="{Binding NAME,UpdateSourceTrigger=PropertyChanged}" Visibility="Visible" MinWidth="180"/>
<DataGridTextColumn Header="کد کالا" x:Name="CODEKALA_COL" Binding="{Binding CODEKALA,UpdateSourceTrigger=PropertyChanged}" Visibility="Hidden" MinWidth="80"/>
</DataGrid.Columns>
</DataGrid>
C#:
private void DGR_SUB_INVOLST_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (DGR_SUB_INVOLST != null)
{
if (DGR_SUB_INVOLST.Items.Count > 0)
{
(e.Row.Item as INVOMonitor).CODE = 1;
//Refresh here :
DGR_SUB_INVOLST.Items.Refresh();
DGR_SUB_INVOLST.BeginEdit();
DGR_SUB_INVOLST.CommitEdit();
DGR_SUB_INVOLST.InvalidateVisual();
DGR_SUB_INVOLST.UpdateLayout();
}
}
}
结果:enter image description here实际上项目行确实已更改,但未显示!
都不行!2请指导我
1条答案
按热度按时间58wvjzkj1#
我认为您应该像这样修改
Cell
:1-正在获取
Column
与Row
索引:2-获取单元格的方法:
使用方法: