Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1180
Not enough context to add a new row
posted

Lets consider following sample : grid with some columns, refresh button on it, grouping available.

private void Form1_Load(object sender, EventArgs e)
{ Initialize(); }

private void ultraButtonRefresh_Click(object sender, EventArgs e)
{ dataTable1.Rows.Clear();  Initialize(); }

private void Initialize()
{
    for (int y = 0; y < 10; y++)
    {
        UltraGridRow row = m_grid.DisplayLayout.Bands[0].AddNew();
        row.Cells[0].Value = y;
    }
}

Important thigs from designer.cs:

- ultraGridBand1.RowLayoutStyle = Infragistics.Win.UltraWinGrid.RowLayoutStyle.GroupLayout;
- this.m_grid.DisplayLayout.Override.AllowGroupBy = Infragistics.Win.DefaultableBoolean.True;
- this.m_grid.DisplayLayout.ViewStyleBand = Infragistics.Win.UltraWinGrid.ViewStyleBand.OutlookGroupBy;

Case 1: When rows are by grouped by one column (in designer) rows do not appear silenty, or sometimes exception does happen, behaviour incosistent, depends if there were groups in row layout designer :

2. When we are not grouped, everything loads OK, addnew somehow figures out the active row which gives it loading context:

3. Bad things start to happen if we have app, as code above - in our app grid starts as not grouped, then user performs grouping and then clicks refresh.

Following exception is then raised:

System.InvalidOperationException was unhandled
  Message=Not enough context to add a new row. Either a row in this band or the parent band has to be active to provide for enough context.
  Source=Infragistics2.Win.UltraWinGrid.v11.1
  StackTrace:
       at Infragistics.Win.UltraWinGrid.UltraGridBand.AddNew(Boolean calledFromAddNew)
       at Infragistics.Win.UltraWinGrid.UltraGridBand.AddNew()
       at infra1.Form1.Initialize() in C:\C#\infra\infra4\infra1\Form1.cs:line 35     

 

Case is obvious - the control does not know where to put newly created row, as values for each of grouping column have to be provided.

But we are about to fill values which would allow to do that - is there a way to perform two step row adding, as in DataTable - create + fill + insert?

Maybe it would be possible to somehow suspend synchronization for time of value filling to new row?

I know there are ways of adding row to datasource etc, but #3 is exactly the bug we are getting and looking for an easy way to fix exactly such a situation.

Parents
No Data
Reply
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    The first thing I recommend is that you get the latest service release. We recently fixed a bug that occurred when adding new rows to the grid while the grid is grouped.

    How to get the latest service release - Infragistics Community

    If that does not help, then it's possible that the grid really cannot add the new row because of a lack of context. Typically, this only happens when adding child rows, though. I've never seen it happen at the root level, even when the grid is grouped.

    If there is an issue there, then I would recommend saving the grid's DisplayLayout into a MemoryStream. Then Reset the Layout so as to remove the grouping. Then add all of the rows. And then load the layout back into the grid.

Children