【问题标题】:Application hangs/freezes when setting RadGridView datasource设置 RadGridView 数据源时应用程序挂起/冻结
【发布时间】:2016-03-02 13:22:44
【问题描述】:

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

我能做些什么来加载数据源而不丢失我的 radgrid 的格式?

最好的问候

【问题讨论】:

  • 您是否有任何格式化事件,例如CellFormatting?你的网格到底丢失了什么格式?
  • 你能上传一个小样本来演示这个问题吗?

标签: c# winforms telerik radgrid radgridview


【解决方案1】:

From the telerik docs:

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

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

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

【讨论】:

  • 我的收藏只有 20 行,它应该是一个流畅的过程......将 AutoGenerateColumns 设置为 false 并没有解决问题。我想不通。当我调试应用程序时,设置数据源时会挂起......无论如何,谢谢
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    相关资源
    最近更新 更多