gpt4 book ai didi

c# - DataGrid 到 DataRowView

转载 作者:行者123 更新时间:2023-11-30 16:29:18 26 4
gpt4 key购买 nike

我需要在用户点击时从 dataGrid 中收取项目值,将其放入数据行 View 中以获取第一个值“IdEmployee”并分配给变量。

这是我的方法,问题是我的变量 dataRowView 是 Null!

我该如何解决这个问题?

private void _employeedataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataRowView dataRowView = _employeedataGrid.CurrentCell.Item as DataRowView;
var idEmployee = Convert.ToInt32(dataRowView.Row[0]);

.......
}

最佳答案

那是因为 _employeedataGrid.CurrentCell.Item 不能转换为 DataRowView。为什么不尝试使用 CurrentRow 而不是 CurrentCell?:

private void _employeedataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
DataRowView dataRowView = _employeedataGrid.CurrentRow.Item as DataRowView;
var idEmployee = Convert.ToInt32(dataRowView.Row[0]);
.......
}

关于c# - DataGrid 到 DataRowView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6391479/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com