c# - 从 wpf datagrid 获取隐藏值

标签 c# wpf datagrid

我可以从 DataGrid 中获取隐藏列的值吗?

<DataGridTextColumn Header="" Width="10" Binding="{Binding id}"  Visibility="Hidden"/>

使用这段代码,我得到异常。

Data.IdServ = ((TextBlock)DataGridService.Columns[1].GetCellContent(row)).Text;


if (dgUserEnroll.SelectedItem != null)
{
  var data = (User)dgUserEnroll.SelectedItem;
  var userID = data.UserId;
 }

这不是一个选项,因为我在接收数据时有 tableadapter

最佳答案

您也可以在后面使用您的代码。您只需要以不同的方式隐藏该列:

<DataGridTextColumn Header="" MaxWidth="0" Binding="{Binding id}" />

即删除 Visibility 属性并将 MaxWidth 设置为零。

关于c# - 从 wpf datagrid 获取隐藏值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33412875/

相关文章:

c# - 我如何检查 DateTime 是否为空

c# - 为什么切换按钮的 guard 属性在其名称与属性匹配时会被忽略?

.net - 无法在此事件处理程序中执行操作

c# - 填充 DataGrid : how to manipulate data before showing it on C# MySQL

c# - Entity Framework 中的 ICollection<T> 与 List<T>

c# - Winforms Devexpress 应用部署

c# - 如何将子用户控件中的按钮链接到父级。 C#/WPF

wpf - 应用程序设置中的VB.Net WPF键值对字典

c# - WPF - 图像源 - 不在预期范围内

c# - 我们如何在 wpf 中使用数据网格?