【问题标题】:Telerik radgridview CellFormatting is not stableTelerik radgridview CellFormatting 不稳定
【发布时间】:2019-08-15 01:28:05
【问题描述】:

我有一个包含许多列的 radgridview(水平滚动条已被激活)。
我的网格中有一个 CommandColumn,我想像这样格式化它:

private void rad_grd_Requests_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement.ColumnInfo is GridViewCommandColumn)
        {
            RadButtonElement button = (RadButtonElement)e.CellElement.Children[0];
            if (e.CellElement.RowInfo.Cells["Admin_Action"].Value.ToString() == "Hold")
            {
                button.Text = "Done";
            }
            else
            {
                button.Text = "Done";
                button.Visibility = ElementVisibility.Hidden;
            }
        }
    }

程序启动后一切正常。
但是当我有时使用网格的水平滚动条时,CommandColumn 中的所有按钮都是不可见的。(多次运行 CellFormatting())
为什么 CellFormatting() 不稳定&我该如何解决这个问题?

【问题讨论】:

    标签: c# winforms telerik radgridview


    【解决方案1】:

    这是答案:

       RadButtonElement button = (RadButtonElement)e.CellElement.Children[0];
        if (e.CellElement.RowInfo.Cells["Admin_Action"].Value.ToString() == "Hold")
        {
            button.Text = "Done";
            button.Visibility = ElementVisibility.Visible;
        }
        else
        {
            button.Text = "Done";
            button.Visibility = ElementVisibility.Hidden;
        }
    

    将button.Visibility = ElementVisibility.Visible; 添加到您的代码中。

    【讨论】:

      【解决方案2】:

      由于 RadGridView 中的 UI 虚拟化,单元格元素仅针对当前可见的单元格创建,并且在滚动、过滤、分组等操作期间被重用。为了防止将格式应用于其他列的单元格元素(因为单元格重用),应为其余单元格元素重置所有自定义。

      请参考以下帮助文章,演示如何正确自定义单元格并重置样式:https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells

      我希望这些信息对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-25
        • 1970-01-01
        • 2016-01-14
        • 1970-01-01
        • 1970-01-01
        • 2013-01-27
        • 1970-01-01
        相关资源
        最近更新 更多