enable отключить, разрешить добавление новой строки в дочерний шаблон Telerik Grid - PullRequest
1 голос
/ 08 сентября 2011

Кто-нибудь знает, возможно ли программно включить или отключить функцию добавления новой строки в сетке telerik в дочернем шаблоне?

У меня есть ряд строк и дочерний шаблон для каждой строки. Для некоторых строк я хочу, чтобы пользователь мог выполнять операции над дочерним шаблоном, для других - нет.

Мне трудно найти экземпляр дочернего шаблона, когда отображается сетка.

Этот вопрос для winforms telerik.

1 Ответ

1 голос
/ 09 сентября 2011

Требуется немного работы, но это возможно. Я проверил следующий код, и он работает. Надеемся, что комментарии делают это само за себя:

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