Insert row in grid after last current position

As the title says, lately I've been getting this request a lot: insert the newly created row after the last position, or otherwise said insert it at the bottom of the grid.

Thanks to some colleagues of mine, the answer came quite fast, after initially dismissing quite easy the request on the grounds that it will be rather cumbersome ... the solution I must admit is extremely simple and elegant; depending on how you call this you will need to do:

    dataSourceVariable_ds.last();
    dataSourceVariable_ds.create(true);

The code speaks for itself: just move the cursor in the grid on the last position and then create the record after the current position (this is what the true parameter does).

2 comments:

  1. Good information to know, but can you please add where this method should be written inside the Form?

    ReplyDelete
    Replies
    1. You add this code (the two lines of code) to any button's clicked override method, or if you want this to happen all the times, just override the Create method for your dataSource and add it.

      Delete