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

Prevent grouping when edit/insert

5 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 21 Jan 2013, 03:58 PM
Hello,

I want to prevent the user from grouping when the grid is currently in edit or insert mode.
For the sort command, I did this in GridItemCommand:

public bool IsInEditMode
      {
         get { return MasterTableView.IsItemInserted || EditItems.Count > 0; }
      }
 
 
private void _GridItemCommand(object sender, GridCommandEventArgs e)
{
     if (IsInEditMode &&
             e.CommandName == RadGrid.SortCommandName)
         {
            e.Canceled = true;
         }

But the grouping won't call the GridItemCommand event handler. How can I cancel the grouping?

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2013, 04:39 AM
Hi,

Please try the following code snippet to prevent Grouping on edit/Insert.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        RadGrid1.GroupingEnabled = false;
        RadGrid1.ShowGroupPanel = false;
    }      
}

Thanks,
Shinu.
0
JP
Top achievements
Rank 1
answered on 22 Jan 2013, 08:52 AM
Hi,

this will indded disable the grouping, but when the grid leaves the edit mode, the grouping panel is still disabled although the Grouping gets enabled in OnLoad (including ShowGroupPanel=true).
0
Shinu
Top achievements
Rank 2
answered on 22 Jan 2013, 09:11 AM
Hi,

Please try the following code snippet as well.

C#:
protected void Page_Load(object sender, EventArgs e)
{
   RadGrid1.GroupingEnabled = true;
   RadGrid1.ShowGroupPanel = true;     
}

Thanks,
Shinu.
0
JP
Top achievements
Rank 1
answered on 22 Jan 2013, 10:33 AM
The second snippet works, but after a postback (e.g. in the edit form) the Grouping gets enabled again.
It seems that I need to disable the GroupingPanel/GroupPanel in a method which will get called during every postback. Would the Grid's PreRender event handler be the best place for this?
0
Shinu
Top achievements
Rank 2
answered on 23 Jan 2013, 04:02 AM
Hi,

Please try the following code snippet in the PreRender event.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
         RadGrid1.GroupingEnabled = true;
         RadGrid1.ShowGroupPanel = true;
         RadGrid1.Rebind();    
}

Thanks,
Shinu.
Tags
Grid
Asked by
JP
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JP
Top achievements
Rank 1
Share this question
or