我是 wpf 数据网格的新手。我从数据网格中的非隐藏字段中获取值,但如果该字段设置为隐藏,它将返回空值。我将列表绑定到数据网格。
<my:DataGrid RowHeight="30" ColumnWidth="50" AutoGenerateColumns="False" Margin="20,17,0,0" Name="dgUserEnroll" ItemsSource="{Binding}" Background="{StaticResource buttonFlash}" HorizontalAlignment="Left" Width="292" CanUserResizeColumns="False" CanUserAddRows="True" CanUserDeleteRows="True" RowDetailsVisibilityMode="Visible" Height="194" VerticalAlignment="Top">
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="id" Width="*" Binding="{Binding Path=UserID}" Visibility="hidden"/>
<my:DataGridTextColumn Header="UserName" Width="*" Binding="{Binding Path=AdminName}" />
<my:DataGridTextColumn Header="Role" Width="*" Binding="{Binding Path=RoleName}" />
</my:DataGrid.Columns>
</my:DataGrid>
C# Code behind:
//To get values from 0th index.
var UsrID = DatagridUtilities.GetCell(this.dgUserEnroll, rowIndex, 0);
user.UserID = int.Parse((UsrID.Content as TextBlock).Text.ToString());