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
I am adding a new row by using .DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnBottom
each time I click on other row the other row disappears.Can you please help me?
Hi Paul,
That's not possible. You cannot leave the AddNew row without either committed it or cancelling it. This is a function of the BindingManager in DotNet which implicitly performs an update any time the position of the BindingManager changes.
Mike,
Well, I am back to 2 replies ago. As you indicated, it is wanting to save a blank row into the database. I did check the grid datachanged propoerty and it is false, however, the dataset haschanges properties is true so it saves the blank row into the database. This absolutely is not what I want.
Here is the question then which I did put in a previous reply. If I want an addnew row to be always be displayed at the bottom of the grid, how do I do this without the row disappearing when going to a row with data and also not add a blank record into the database?
Paul
Disregard the previous reply. I added an IFstatement in the AfterRowUpdate event to check the activerow datachanged property. The datachanged is false, so I do not update the data. Once I added this, the templaterow does not disappear as you have indicated. I had an issue where after setting the AddRowModifiedByUser to true in one part of my code, this value was reset to false. I moved the logic into the InitializeLayout event and everything works correctly now.
Thank you for your help.
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