设置 RadGridView 数据源时应用程序挂起/冻结



我有一个winforms应用程序,当我最小化窗口时,我需要进程仍在运行。在我设置 RadGrid 数据源之前一切都没问题:radGrid1.DataSource = datasource1;当我以这种方式设置数据源时,应用程序只会冻结,没有任何反应。经过一些搜索,我将代码修改为: radGrid1.BeginUpdate(); radGrid1.DataSource = datasource1;这样我就可以设置数据源,但我的网格丢失了格式。如果我添加radGrid1.EndUpdate()它也会冻结。

我可以怎么做才能加载数据源并且不丢失辐射网格的格式?

此致敬意

来自 telerik 文档:

若要防止网格遍历该集合中的所有数据字段,请将 GridViewTemplate.AutoGenerateColumns 属性设置为 False。在这种情况下,排序、分组等时可能使用的其他字段应包含在 MasterGridViewTemplate.Columns 集合中。使用这些设置,将仅提取用作列字段名称属性的属性或在 MasterGridViewTemplate.Columns 中指定的属性。

应该解决您描述的"丢失格式"的问题。第二个问题,程序冻结,不是我在Windows窗体环境中使用RadGridViews的许多场合遇到的问题。

我唯一能想到的是您的数据源集合太大,或者集合中的项目有太多字段,当 AutoGenerateColumns 属性设置为 true 时,RadGridView 会尝试为其生成列。

我今天刚刚在使用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);
        }
    }

模型中实际上缺少这两个字段,添加它们解决了应用程序挂起的问题。该问题似乎与格式化功能有关,因为删除它也会阻止应用程序挂起。

最新更新