Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在telerik网格的子模板上启用或禁用“允许添加新行”_C#_Winforms_Grid_Telerik - Fatal编程技术网

C# 在telerik网格的子模板上启用或禁用“允许添加新行”

C# 在telerik网格的子模板上启用或禁用“允许添加新行”,c#,winforms,grid,telerik,C#,Winforms,Grid,Telerik,是否有人知道是否可以通过编程方式在子模板中启用或禁用telerik网格的“添加新行”功能 我有一系列的行和每行的子模板。对于某些行,我希望用户能够对子模板执行操作,而对于其他行,我不希望 当网格显示时,我很难找到子模板的实例 这个问题是给winforms telerik的 这需要一些工作,但这是可能的。我测试了下面的代码,它运行正常。希望这些评论能够不言自明: //Attach an event handler for CreateRowInfo on the child template th

是否有人知道是否可以通过编程方式在子模板中启用或禁用telerik网格的“添加新行”功能

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

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


这个问题是给winforms telerik的

这需要一些工作,但这是可能的。我测试了下面的代码,它运行正常。希望这些评论能够不言自明:

//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;
}