This is a migrated thread and some comments may be shown as answers.

CellBeginEdit in hierarchy

1 Answer 69 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Peter Luth
Top achievements
Rank 1
Peter Luth asked on 25 Aug 2009, 12:15 PM
Hello,

I'm using CellBeginEdit event on RadGridView to optionally cancel the edit depending on the contents on the cell. Some example code is below.

But what if the cell is edited is not in the top level hierarchy? I'm using a hierarchy gridview with relations. RowIndex cannot tell me this. How can I know this? I just want to access the DataBoundItem on the current editing cells row.

public static void CellBeginEdit_ReadonlyRows(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e) 
    if (e.RowIndex == -1) 
         return; 
 
    RadGridView gridView = sender as RadGridView; 
 
    if (gridView == null) 
         return; 
 
    MyEditableEntry groupItem = gridView.Rows[e.RowIndex].DataBoundItem as MyEditableEntry; 
 
    if (groupItem == null || !groupItem.IsEditable) 
         e.Cancel = true
    else 
         e.Cancel = false
 


1 Answer, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 25 Aug 2009, 10:44 PM
Hi Peter,

You should be able to access the currently selected cell through the CurrentCell property of the gridview.

public static void CellBeginEdit_ReadonlyRows(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e)  
{  
    if (e.RowIndex == -1)  
         return;  
  
    RadGridView gridView = sender as RadGridView;  
  
    if (gridView == null)  
         return;  
  
    //MyEditableEntry groupItem = gridView.Rows[e.RowIndex].DataBoundItem as MyEditableEntry;
    MyEditableEntry groupItem = gridView.CurrentCell.RowInfo.DataBoundItem as MyEditableEntry; 
 
    if (groupItem == null || !groupItem.IsEditable)  
         e.Cancel = true;  
    else  
         e.Cancel = false;  
}  

I hope this helps.

- Robert
Tags
GridView
Asked by
Peter Luth
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Share this question
or