我需要在用户单击时从dataGrid收取项目值,并放入datarowview中以获取第一个值“ 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]);
.......
}