Still Cannot Insert Second Row - FlexGrid VB.NET

Posted by: mwebster on 15 March 2021, 1:16 pm EST

    • Post Options:
    • Link

    Posted 15 March 2021, 1:16 pm EST

    I posted something on this before and thought I had sorted it out but that is not the case. Unfortunately, the example given was in c# which I am not familiar with so it was not particularly helpful.

    I have a Flexgrid on a form bound to a datatable. I am using the AfterEdit even to update the underlying database when the user inserts a row. The first row insert works fine. Any subsequent rows are not added to the database unless I reload the datatable and re-populate the flex grid. After the first row is inserted, the new row appears in the grid. When you type in values and finish editing, the new row simply vanishes.

    Again, it is VB not C# and I am using the AfterEdit event to update existing rows/insert new rows. I was able to determine that the AfterEdit event does not even fire when adding the second row. I tried using the flexgrid.finishEditing method which did not have any effect.

    What am I missing here?

  • Posted 15 March 2021, 1:17 pm EST

    Sorry - this was the original post on the topic.

    https://www.grapecity.com/forums/winforms-edition/flexgrid-oddity---cannot-i

  • Posted 16 March 2021, 1:12 am EST

    Hi,

    After you edit a cell, the row is not immediately added to the underlying data table until you moved the cursor to a new row or the grid loses focus. This is the design behavior because row-level validation often cannot be performed until all the fields in the row have been edited. However, you can force commit the changes to the data table by using the CurrencyManager.EndCurrentEdit method.

    You need to commit the changes in your AfterEdit event handler before updating the database.

    Please refer to the sample attached.

    Regards.

    Avnish

    FlexGridRowUpdate2.zip

  • Posted 16 March 2021, 6:42 am EST

    Thank-you, I will check it out and get back to you.

  • Posted 16 March 2021, 10:11 am EST

    This doesn’t solve the problem but it does appear to have identified the specific issue. When I use this method, the cm.EndCurrentEdit method returns an error saying that the value CatalogCodeID has a null value. The problem is that the code I execute to update the database inserts the value into that field in the database but not into the datatable referenced by the control. This explains why re-loading the datatable solves the error (but causes the problem of throwing the user off the current row in the flexgrid).

    If I can manually update the datatable as well as the database, that should resolve this issue.

  • Posted 16 March 2021, 10:56 am EST

    Looks like using AfterValidate solves the issue. Thanks for your help.

  • Posted 17 March 2021, 2:06 am EST

    Glad, we could help.

    Regards.

    Avnish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels