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
115
Grid adding dual rows in dataset
posted

Hi,

I'm having a problem with my datagrid.  The issue is that when I first click on the AddNewBox, the AfterRowInsert event is fired and an empty row is added to both the datagrid and the underlying datasource (DataTable).  After inputting the data and leaving the AddNewBox, the AfterRowUpdate event is fired.  Immediately after this, the AfterRowInsert event is fired again as focus is again placed on the AddNewBox.  If I click away immediately from the AddNewBox at this point the AfterRowUpdate event is not fired again.

The problem with this is that there does not appear to be a way to tell if a row is new or if a row is an update of a current row, which is important for database operations.  I have tried the isNewRow, but that property is false in the AfterRowUpdate method.  I have also tried setting the Nullable property of the column to EmptyString and Null, but I don't believe that setting does what I would like. 

Does anyone have any insight or ideas that I could try?  Perhaps there is a better way to add new rows or set up the datagrid to allow the functionality to work more intuitively.

Trevor

  • 115
    posted

    The answer to this issue appears to be using the bound datatable.  The datatable will track an added row using the Rowstate property.  The UltraGrid does not add a record to the datatable unless data is entered into the visible cells in the NewRow row, so you can use the OnInsert event to create a primary key and the OnUpdate event to determine whether a row is new using the RowState property of the newly added/updated row in the datatable.  Then insert/update in the database accordingly.

    Another reason for this issue is that a row cannot be inserted in the UltraGrid because the grid requires a primary key before a row is initially added.  This is probably a property possibly taken from the primary key field in the datatable.  Another workaround may have been to remove the primary key from the datatable, then do your insert/update statement in the OnUpdate event.

     Trevor