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

Expand item on edit?

3 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lucania
Top achievements
Rank 1
Lucania asked on 20 Jul 2011, 03:09 AM
Hi,

I have a RadGrid with an EditItemTemplate and a DetailTable. I would like for the detail to be displayed when I edit an item, and have the following code in my ItemCommand event:
switch (e.CommandName)
{
    case RadGrid.EditCommandName:
        e.Item.OwnerTableView.IsItemInserted = false;
        e.Item.Expanded = true;
        break;
    case RadGrid.InitInsertCommandName:
        // Cancel any edit form
        foreach (GridItem item in e.Item.OwnerTableView.Items)
        {
            if (item is GridEditableItem)
            {
                GridEditableItem ei = item as GridEditableItem;
                ei.Edit = false;
            }
        }
        break;
    default:
        break;
}

But when I click edit, the form is displayed but the item does not expand. I have checked that no other code is being executed that might do a Rebind().

Any reason this might be happening?

ROSCO

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jul 2011, 07:53 AM
Hello Ross,
Try the following approach in to achieve your scenario.
C#:
int flag=0, row;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
   if (e.Item is GridEditFormItem && e.Item.IsInEditMode && e.Item.OwnerTableView.Name == "Master")
    {
       GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
       GridDataItem item = (GridDataItem)editFormItem.ParentItem;
       flag = 1;
       row = item.ItemIndex;
    }
 }
protected void RadGrid1_PreRender(object sender, EventArgs e)
 {
   if(flag == 1)
    {
      RadGrid1.MasterTableView.Items[row].Expanded = true;
    }
 }

Thanks,
Shinu.
0
Lucania
Top achievements
Rank 1
answered on 21 Jul 2011, 01:01 AM
Thanks Shinu, that works great.

I was experimenting to see if there's any way to do it without using the ItemDataBound event, but I can't find any way to determine whether a particular GridItem is in edit mode in the PreRender event. It seems the IsInEditMode flag is false for all the GridItems and GridDataItems in the PreRender. Is there no way to determine this except in the ItemDataBound event?

Thanks

ROSCO
0
Lucania
Top achievements
Rank 1
answered on 21 Jul 2011, 03:36 AM
I had to add the following test to the ItemDataBound, to cater for insert mode:
if (item != null)
{
   flag = 1;
   row = item.ItemIndex;
}

Regards
ROSCO
Tags
Grid
Asked by
Lucania
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Lucania
Top achievements
Rank 1
Share this question
or