Infragistics Net Advantage Version 11.1.20111.2009
In Visual Studio 2008, I have a ultragrid bound to a bindingsource. I also have a bindingnavigator toolstrip on the form. I have a templateaddrow activated showing the add new row at the bottom of the grid. By default, the form loads and the cursor is located in the add new row, first field. When I click on a grid row with data, the addnew row disappears (this also happens when I click the cancel button in the navigator which issues the command grid.activerow.cancelupdate). How can I keep the addnew row from disappearing? To resolve this, if the user clicks the Add New in the navigator control, I execute the command grid.rows.templateaddrow.active and the addnew row comes back.
I thought that this might be related to having the grid bound to a bindingsource, but I changed my logic and bound the data directly to a dataset, and the same problem occurs. Here is my code (I have the bindingsource lines commented out to test the dataset) - (also, as a side note, pressing the ESC key twice also causes the addnew row to disappear and this behaviour does not appear to happen when using Visual Studio 2010):
Try myNoticesDS.Tables.Add("Notices") myNoticesDA.Fill(myNoticesDS.Tables("Notices")) oleCB = New OleDbCommandBuilder(myNoticesDA) myNoticesDA.InsertCommand = oleCB.GetInsertCommand() myNoticesDA.UpdateCommand = oleCB.GetUpdateCommand() myNoticesDA.DeleteCommand = oleCB.GetDeleteCommand()
'MyBindingSource.DataSource = myNoticesDS.Tables("Notices") 'BindFields(Me, "Notices", myNoticesDS, MyBindingSource) 'myBinding = Me.BindingContext(myNoticesDS, "Notices") 'BindingNavigator1.BindingSource = MyBindingSource 'BindingNavigator1.DeleteItem = Nothing 'BindingNavigator1.AddNewItem = Nothing Catch ex As Exception MsgBox(ex.Message) End Try
'grdDataGrid.DataSource = myBindingSource grdDataGrid.DataSource = myNoticesDS With grdDataGrid .Rows.TemplateAddRow.Activate() With .DisplayLayout .Override.RowSelectors = Infragistics.Win.DefaultableBoolean.True .AddNewBox.Hidden = True .Override.HeaderClickAction = Infragistics.Win.UltraWinGrid.HeaderClickAction.SortMulti .Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TabRepeat .Override.AllowAddNew = Infragistics.Win.UltraWinGrid.AllowAddNew.TemplateOnBottom End With End With
Please advise.
Thanks. Paul
Hi Paul,
A TemplateAddRow is not "real" row. It does not exist in the data source.
Once you click on that row, the TemplateAddRow becomes a real row. The grid adds a new row to the data source and a new TemplateAddRow displays below the new AddRow.
But the grid keeps track of whether the AddRow has been modified by the user. If the user clicks on the TemplateAdd and then moves out of that row without modifying anything, it doesn't necessarily make sense to keep that row around, so the grid cancels it. If it did not do this, then your users might end up adding a bunch of blank rows to the data which they didn't intend (or even realize).
Having said all that, if you want the AddRow to act as though it was modified by the user and stick around even after they leave the row, you set the AddRowModifiedByUser property on the Rows collection to true.
this.ultraGrid1.Rows.AddRowModifiedByUser = true;
Mike,
Unfortunately when I do this, as you would think would happen, when I leave the addnew row, the grid trys to save that row even though I have not entered any data. I put a break point in the AfterRowUpdate event and look at value of the AddRowModifiedByUser and it is now false (meaning that this value is reset). Then after the addnew row loses focus, once again the row disappears. I can understand some of what you are saying about it being a template row, but why does VS 2010 not have this same issue? The addnew row does not disappear in that version of studio.
Finally, if this is the correct behaviour for the template row, what is the proper method for having an addnew row at the bottom of the grid and have it always be present?
Thank you. Paul