如下:读取DataGrid中某一单元格的值,然后转换正下拉框,读取下拉框选中的值
有时FrameworkElement selectcbGroupInCell = customVarMESParamDataGrid.Columns[5].GetCellContent(item) ;会返回null,
foreach (var item in customVarMESParamDataGrid.Items)
{
FrameworkElement selectcbGroupInCell = customVarMESParamDataGrid.Columns[5].GetCellContent(item) ;
DataGridTemplateColumn tempGroup = customVarMESParamDataGrid.Columns[5] as DataGridTemplateColumn;
if (selectcbGroupInCell != null && tempGroup != null)
{
ComboBox cbTestGroup = tempGroup.CellTemplate.FindName("cbGroup", selectcbGroupInCell) as ComboBox;
TestGroup tg = cbTestGroup.SelectedItem as TestGroup;
if (tg != null)
{
MesParam.GroupId = tg.ID;
MesParam.GroupName = tg.GroupName;
}
}
}
解决方法:在DataGrid中添加属性 虚拟化设为false:VirtualizingPanel.IsVirtualizing="False",即可解决返回null的问题。