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

C# 设置RadGridView数据源时应用程序挂起/冻结,c#,winforms,telerik,radgrid,radgridview,C#,Winforms,Telerik,Radgrid,Radgridview,我有一个winforms应用程序,当我最小化窗口时,我需要进程仍在运行。在我设置RadGrid数据源之前一切都正常:radGrid1.datasource=datasource1 当我以这种方式设置数据源时,应用程序只是冻结,没有其他事情发生。 经过一些搜索后,我将代码修改为: radGrid1.BeginUpdate(); radGrid1.DataSource=datasource1 这样我可以设置数据源,但是我的网格丢失了格式。 如果我添加radGrid1.EndUpdate()它也会冻结

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

加载数据源时,我能做些什么,而不会丢失我的radgrid格式

致以最诚挚的问候

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

应该修复您描述的“丢失格式”问题。 第二个问题是程序冻结,这不是我在windows窗体环境中多次使用
RadGridViews
时遇到的问题

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

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

应该修复您描述的“丢失格式”问题。 第二个问题是程序冻结,这不是我在windows窗体环境中多次使用
RadGridViews
时遇到的问题


我唯一能想到的是你的数据源集合太大了,或者集合中的项目有太多的字段,
RadGridView
试图为
AutoGenerateColumns
属性设置为
true
时生成列。我今天在使用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);
        }
    }

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

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

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

我的收藏只有20行,这应该是一个流动的过程。。。将AutoGenerateColumns设置为false无法解决问题。我想不出来。当我调试应用程序时,当设置数据源时,应用程序将挂起。。。无论如何谢谢你我的收藏只有20行,它应该是一个流动的过程。。。将AutoGenerateColumns设置为false无法解决问题。我想不出来。当我调试应用程序时,当设置数据源时,应用程序将挂起。。。谢谢您您是否有任何格式化事件,例如
CellFormatting
?你的网格丢失了什么格式?你能在某处上传一个小样本来演示这个问题吗?你有任何格式化事件,例如
CellFormatting
?你的网格丢失了什么格式?你能在某处上传一个小样本来演示这个问题吗?