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

Only edit one row at a time

5 Answers 354 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carl-Johan
Top achievements
Rank 1
Carl-Johan asked on 29 Jun 2010, 06:37 AM
Hi,

I would like to close all rows that are in edit-mode when i click on edit one another row. That way i can only edit one row at a time (locks better).

I would also like this to work the same way when i insert a new row.

How do i do that?

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jun 2010, 07:58 AM
Hello Carl-Johan,

If you want only one row in edit mode you can set AllowMultiRowEdit Property of RadGrid as false. You can refer the following Forum post which explains how to hide editform when clicking insert and vice versa.

Stop Edit and Insert from displaying at the same time

Thanks,
Princy.




0
Carl-Johan
Top achievements
Rank 1
answered on 29 Jun 2010, 08:10 AM
Hi,

Thank you for the quick reply.

The "AllowMultiRowEdit" works great.

But if you have a MasterTable/Childtable it only works on one table at a time.

So if I have the MasterTable in editmod, expand the MasterTable, sets a childrow in editmode the MasterTable is still in editmode.
Is it possible to solve this.
0
Princy
Top achievements
Rank 2
answered on 30 Jun 2010, 02:09 PM
Hello Carl-Johan,

 Here is the sample code that i did in my application to achieve this functionality. In ItemCommand event catch the operation (Insert/Edit), GridTableViewName (Master/DetailTable), and row index of MaterTable and DetailTable by using Session variables. Then in PreRender event, based on the value in Session variable show the insert/edit form in  MasterTable/DetailTable accordingly. I know the code is too grievous, but at present I can't find an alternate method for this.

ASPX:
<MasterTableView Name="Master" runat="server" AutoGenerateColumns="true" DataKeyNames="EmployeeID"  
        CommandItemDisplay="Top">  
        <DetailTables>  
            <telerik:GridTableView Name="GridTableView1" runat="server" AutoGenerateColumns="true"  
                DataKeyNames="EmployeeID" CommandItemDisplay="Top" DataSourceID="SqlDataSource2">  
                <ParentTableRelation>  
                    <telerik:GridRelationFields DetailKeyField="EmployeeID" MasterKeyField="EmployeeID" />  
                </ParentTableRelation>  
                <Columns>  
                    <telerik:GridEditCommandColumn>  
                    </telerik:GridEditCommandColumn>  
                </Columns>  
            </telerik:GridTableView>  
        </DetailTables>  
        <Columns>  
            <telerik:GridEditCommandColumn UniqueName="EditColumn">  
            </telerik:GridEditCommandColumn>  
        </Columns>  
 </MasterTableView>  

C#:
  protected void Page_Load(object sender, EventArgs e) 
    { 
        Session["rowIndex"] = 0; 
        Session["detailIndex"] = 0; 
        Session["operation"] = 0; 
        Session["tableName"] = 0; 
    } 
 
 protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) 
    { 
        Session["operation"]= e.CommandName; 
        Session["tableName"] = e.Item.OwnerTableView.Name; 
        if ((e.CommandName == "InitInsert" || e.CommandName == "Edit")) 
        { 
            if (e.Item.OwnerTableView.Name == "GridTableView1"
            { 
                Session["rowIndex"] = e.Item.OwnerTableView.ParentItem.ItemIndex; 
                Session["detailIndex"] = e.Item.ItemIndex; 
            } 
            else 
            { 
                Session["rowIndex"] = e.Item.ItemIndex; 
            } 
        } 
   } 
 
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    {      
        int rowIndex = Convert.ToInt16(Session["rowIndex"].ToString()); 
        int detailIndex = Convert.ToInt16(Session["detailIndex"].ToString()); 
        if (Session["operation"].ToString()=="InitInsert")             
        { 
            if (Session["tableName"].ToString() == "GridTableView1"
            { 
                RadGrid1.MasterTableView.IsItemInserted = false
                RadGrid1.EditIndexes.Clear(); 
                RadGrid1.MasterTableView.Rebind(); 
                RadGrid1.MasterTableView.Items[rowIndex].Expanded = true
                (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].IsItemInserted = true
                (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].Rebind(); 
             } 
            if (Session["tableName"].ToString() == "Master"
            { 
                RadGrid1.EditIndexes.Clear(); 
                RadGrid1.MasterTableView.Rebind(); 
                RadGrid1.MasterTableView.IsItemInserted = true
            } 
        } 
        if(Session["operation"].ToString()=="Edit"
        { 
            if (Session["tableName"].ToString() == "GridTableView1"
            { 
                RadGrid1.MasterTableView.IsItemInserted = false
                RadGrid1.EditIndexes.Clear(); 
                RadGrid1.MasterTableView.Rebind(); 
                RadGrid1.MasterTableView.Items[rowIndex].Expanded = true
                (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].Items[detailIndex].Edit = true
                (RadGrid1.MasterTableView.Items[rowIndex] as GridDataItem).ChildItem.NestedTableViews[0].Rebind(); 
            } 
            if (Session["tableName"].ToString() == "Master"
            { 
                RadGrid1.MasterTableView.IsItemInserted = false
                RadGrid1.MasterTableView.Rebind(); 
                RadGrid1.MasterTableView.Items[rowIndex].Edit = true
            } 
        } 
    } 

Hope this helps you,
Princy.
0
zel
Top achievements
Rank 1
answered on 29 Sep 2010, 09:24 AM
Hi Princy,

I have the same problem with Carl. I hope that there will be a property to set "allow only one master row expanded". So that, there is no need to code anymore.

Regards,
Lyzel
0
Vasssek
Top achievements
Rank 1
answered on 13 Feb 2012, 04:47 PM
Hello everybody,

I know this is a quite old thread, but... Here is my solution how to deal with only one edit row at a time, no matter it is come from master or detail table. It's been done all in one event - RadGrid1_ItemCommand. Radgrid edit mode has to be set as EditMode="InPlace".
protected void RadGridx_1_OnItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.EditCommandName)
    {
        RadGridx_1.MasterTableView.IsItemInserted = false;
    }
    else if (e.CommandName == RadGrid.InitInsertCommandName)
    {
        RadGridx_1.MasterTableView.ClearEditItems();
    }
    else if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem && !e.Item.Expanded)
    {
        RadGridx_1.MasterTableView.IsItemInserted = false;
        RadGridx_1.EditIndexes.Clear();
        RadGridx_1.MasterTableView.Rebind();
        RadGridx_1.MasterTableView.Items[e.Item.ItemIndex].Expanded = true;
    }
}

I hope it helps somebody from big Telerik community...

Vasssek
Tags
Grid
Asked by
Carl-Johan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Carl-Johan
Top achievements
Rank 1
zel
Top achievements
Rank 1
Vasssek
Top achievements
Rank 1
Share this question
or