我今天刚刚在使用 Telerik RadGridView 2017.2.613.40 的应用程序中遇到了这个问题。我在代码中定义了列:
_grid.Columns.AddRange(
//...more columns
new GridViewCheckBoxColumn
{
Name = "IsSmallLabel",
FieldName = "IsSmallLabel",
MinWidth = 100,
MaxWidth = 100,
IsVisible = true,
ReadOnly = false,
HeaderText = "Small label"
},
new GridViewCheckBoxColumn
{
Name = "IsTechCard",
FieldName = "IsTechCard",
MinWidth = 100,
MaxWidth = 100,
IsVisible = true,
ReadOnly = false,
HeaderText = "Tech card"
});
还有一个 OnCellFormatting 事件:
private void OnCellFormatting(object sender, CellFormattingEventArgs e)
{
try
{
var checkCell = e.CellElement as GridCheckBoxCellElement;
if (checkCell == null) return;
var poItem = e.Row.DataBoundItem as PurchaseOrderItem;
if (poItem == null) return;
if (string.Equals(e.Column.Name, "IsSmallLabel", StringComparison.OrdinalIgnoreCase))
{
checkCell.Visibility = !string.IsNullOrEmpty(poItem.LotNo) ? ElementVisibility.Visible : ElementVisibility.Collapsed;
checkCell.Value = !string.IsNullOrEmpty(poItem.LotNo);
}
else if (string.Equals(e.Column.Name, "IsTechCard", StringComparison.OrdinalIgnoreCase))
{
checkCell.Visibility = poItem.TechnologyCard != null ? ElementVisibility.Visible : ElementVisibility.Collapsed;
checkCell.Value = poItem.TechnologyCard != null;
}
}
catch (Exception ex)
{
_logger.Error(ex);
}
}
模型中实际上缺少这两个字段,添加它们解决了应用挂起的问题。该问题似乎与格式化功能有关,因为删除它也会阻止应用挂起。