2011-09-08 5 views
1

자식 템플릿에서 telerik 그리드의 새 행 추가 기능을 프로그래밍 방식으로 활성화 또는 비활성화 할 수 있는지 아는 사람 있습니까?활성화 허용 telerik 그리드의 하위 템플릿에 새 행 추가 허용

각 행에 일련의 행과 하위 템플릿이 있습니다. 일부 행에 대해서는 사용자가 자식 템플리트에서 작업을 수행 할 수있게하고 다른 행에서는 그렇지 못하게합니다.

그리드가 표시 될 때 하위 템플릿의 인스턴스를 찾는 데 어려움을 겪고 있습니다.

이 질문은 답을 기다리고 있습니다.

답변

1

약간의 작업이 필요하지만 가능합니다. 다음 코드를 테스트 한 결과 작동합니다. 잘하면 주석은 자명하다 :

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