启用禁用允许在 Telerik 网格的子模板上添加新行

发布于 2024-12-03 18:46:21 字数 172 浏览 2 评论 0原文

有谁知道是否可以以编程方式启用或禁用子模板中 Telerik 网格的添加新行功能?

我有一系列行和每行一个子模板。对于某些行,我希望用户能够对子模板执行操作,而对于其他一些行,我则不能。

当网格显示时,我很难找到子模板的实例。

这个问题是针对 winforms telerik 的。

Does anyone know if it is possible to programatically enable or disable the add new row feature of the telerik grid in a child template ?

I have a series of rows and a child template for each row. For some rows I want the user to be able to perform operations on the child template, for some other rows i don't.

I am having a hard time finding the instance of the child template when the grid get's displayed.

This question is for winforms telerik.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱没勇气 2024-12-10 18:46:21

这需要做一些工作,但这是可能的。我测试了以下代码并且它有效。希望这些评论能够不言自明:

//Attach an event handler for CreateRowInfo on the child template that you want
//   to control the Add Row feature in Form_Load or somewhere.
//If you just have one template, you could use radGridView1.MasterTemplate.Templates[0]
template.CreateRowInfo += new GridViewCreateRowInfoEventHandler(template_CreateRowInfo);

private void template_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e)
{
    //If we aren't dealing with the New Row, ignore it
    if (!(e.RowInfo is GridViewNewRowInfo))
        return;

    //Grab our parent's info (we need the parent because the parent is the
    //   one that has the actual data.  The new row isn't bound to anything
    //   so it doesn't really help us.)
    var parentInfo = (GridViewHierarchyRowInfo) e.RowInfo.Parent;

    //Make sure the parentInfo isn't null.  This method seems to be called
    //   more than once - and some of those times the parent is null
    if (parentInfo == null)
        return;

    //We can now grab the actual data for this row.  In this case, the grid
    //   is bound to a bunch of Employees
    var rowData = (Employee)parentInfo.DataBoundItem; 

    //Do some test on the data to figure out if we want to disable add
    if(rowData.Name == "Can't Add On Me")
        //If so, we make this row (the 'New Row' row) not visible
        e.RowInfo.IsVisible = false;
}

It takes a little work but this is possible. I tested the following code and it works. Hopefully the comments make it self-explanatory:

//Attach an event handler for CreateRowInfo on the child template that you want
//   to control the Add Row feature in Form_Load or somewhere.
//If you just have one template, you could use radGridView1.MasterTemplate.Templates[0]
template.CreateRowInfo += new GridViewCreateRowInfoEventHandler(template_CreateRowInfo);

private void template_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e)
{
    //If we aren't dealing with the New Row, ignore it
    if (!(e.RowInfo is GridViewNewRowInfo))
        return;

    //Grab our parent's info (we need the parent because the parent is the
    //   one that has the actual data.  The new row isn't bound to anything
    //   so it doesn't really help us.)
    var parentInfo = (GridViewHierarchyRowInfo) e.RowInfo.Parent;

    //Make sure the parentInfo isn't null.  This method seems to be called
    //   more than once - and some of those times the parent is null
    if (parentInfo == null)
        return;

    //We can now grab the actual data for this row.  In this case, the grid
    //   is bound to a bunch of Employees
    var rowData = (Employee)parentInfo.DataBoundItem; 

    //Do some test on the data to figure out if we want to disable add
    if(rowData.Name == "Can't Add On Me")
        //If so, we make this row (the 'New Row' row) not visible
        e.RowInfo.IsVisible = false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文