Telerik radgridview CellFormatting不稳定

问题描述 投票:0回答:2

我有一个包含许多列的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
2个回答
1
投票

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

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

我希望这个信息帮助。


0
投票

这是答案:

   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;添加到您的密码。

© www.soinside.com 2019 - 2024. All rights reserved.