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.
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.
Hi Mike,
I am facing the problem as below.
I am want to use one of my Ultragrid private control from one of my unit tests project.
I am trying to create one Ultragrid control at runtime, where as after binding Datasource i should get UltraGrid.Rows.Count > 0.
where as i am getting row count is 0. no idea why its happening. can you please check and let me know what is wrong with below code.
//Create a table that will contain three columns. Infragistics.Win.UltraWinGrid.UltraGrid tempUltraGrid = new Infragistics.Win.UltraWinGrid.UltraGrid(); DataTable table = new DataTable("Table");
//Create three columns that will hold sample data. DataColumn ApplicationInfo = new DataColumn("ApplicationInfo", typeof(string)); DataColumn ApplicationName = new DataColumn("ApplicationName", typeof(string)); DataColumn Description = new DataColumn("Description", typeof(string)); DataColumn Version = new DataColumn("Version", typeof(string)); DataColumn Type = new DataColumn("Type", typeof(string)); DataColumn FileName = new DataColumn("FileName", typeof(string)); DataColumn Default = new DataColumn("Default", typeof(string));
//Add the three columns to the table. table.Columns.AddRange(new DataColumn[] { ApplicationInfo, ApplicationName, Description, Version, Type, FileName, Default });
//Add the table to the dataset. dsgridSource.Tables.Add(table); dsgridSource.Tables[0].Rows.Add(new object[] { "ApplicationInfo", "ApplicationName1", "Description1", "Version1", "Type1", "FileName1", "Default1" }); tempUltraGrid.DataMember = "Table"; tempUltraGrid.DataSource = dsgridSource;
tempUltraGrid.DisplayLayout.Rows[0].Selected = true; -----Getting error at this line
Error information is :"Index was outside the bounds of the array."
please let me know whatz wrong in the above code
-Hari
Hari,
The problem here is that the grid which you instantiated in code has never been added to the Form. The grid must be added to a Form and the Form must be shown, otherwise even after setting the DataSource of the grid there will be no rows in it. I have attached a sample application which contains your code, slightly re-arranged, and you will see that the grid does contain the row that you added. I hope this is helpful. Let me know if you have further questions.
Actually, the control does not have to be added to a form. But if the control is not added to a form, it will have no BindingContext and without a BindingContext, it cannot get data.
So another potential solution is to simply set the BindingContext to the BindingContext of the form, or to a new BindingContext.