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

Only allow one edit or insert in a RadGrid?

8 Answers 471 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 22 Jul 2010, 06:37 PM

I'm using the Telerik rad grid and I'm allow the user to enter data directly to the grid.

I am using the "EditForms" edit mode and I also allow inserts using the same.

If the user edits a row, then I don't want to allow any other edits or inserts until the current one is complete or cancelled.

I'm totally new to Radgrids and I've recently been working in MVC... so any help would be great!

8 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Jul 2010, 06:10 AM
Hello,


Use the following code snippet in order hide editform when insert form is showing and vice versa.

C#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == RadGrid.EditCommandName) 
    
        RadGrid1.MasterTableView.IsItemInserted = false
    
    if (e.CommandName == RadGrid.InitInsertCommandName) 
    
        RadGrid1.MasterTableView.ClearEditItems(); 
    
}


-Shinu.
0
Chris
Top achievements
Rank 1
answered on 23 Jul 2010, 08:46 PM
Perfect. Thanks! :)
0
Johan
Top achievements
Rank 1
answered on 07 Nov 2012, 01:19 PM
Thanks! 
But this only works between edit and inserts,

How can you allow only one insert at a time using a detail table?
0
Greg
Top achievements
Rank 2
answered on 08 Nov 2012, 09:24 PM
I have the same question, I'm looking for the solution when using "inplace" editing also.
Thanks!
0
gc_0620
Top achievements
Rank 1
answered on 08 Nov 2012, 09:53 PM

Hi,

See this below works?. This solution was provided by Princy some years ago.

Thanks
gc_0620

______

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
       RadGrid grid = (source as RadGrid);
 
        if (e.CommandName == RadGrid.InitInsertCommandName &&  e.Item.OwnerTableView.Name == "Master")  
            // If insert mode, disallow edit
        {
            grid.MasterTableView.ClearEditItems();
        }
        if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name == "Master") // If edit mode, disallow insert
        {
            e.Item.OwnerTableView.IsItemInserted = false;
        }
        if (e.CommandName == RadGrid.ExpandCollapseCommandName) // Allow Expand/Collapse one row at a time
        {
            foreach (GridItem item in e.Item.OwnerTableView.Items)
            {
                if (item.Expanded && item != e.Item)
                {
                    item.Expanded = false;
                }
            }
        }
}

 

0
gc_0620
Top achievements
Rank 1
answered on 09 Nov 2012, 12:48 AM

Hi. Please try this for Detail Table.

Thanks
gc_0620

==============

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        RadGrid grid = (source as RadGrid);
 
        if (e.CommandName == RadGrid.InitInsertCommandName && e.Item.OwnerTableView.Name == "Detail")
        // If insert mode, disallow edit
        {
            e.Item.OwnerTableView.ClearEditItems();
        }
 
        if (e.CommandName == RadGrid.EditCommandName && e.Item.OwnerTableView.Name == "Detail") // If edit mode, disallow insert
        {
            e.Item.OwnerTableView.IsItemInserted = false;
        }
 
        if (e.CommandName == RadGrid.ExpandCollapseCommandName) // Allow Expand/Collapse one row at a time in Master Table
        {
            foreach (GridItem item in e.Item.OwnerTableView.Items)
            {
                if (item.Expanded && item != e.Item)
                {
                    item.Expanded = false;
                }
            }
        }
    }

0
Johan
Top achievements
Rank 1
answered on 09 Nov 2012, 05:18 AM
This is perfect thank you!!!!!!
0
Greg
Top achievements
Rank 2
answered on 12 Nov 2012, 02:32 PM
This works great for my solution, thanks!!
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Johan
Top achievements
Rank 1
Greg
Top achievements
Rank 2
gc_0620
Top achievements
Rank 1
Share this question
or