How AddRowToDataSource works ?

Posted by: vjoy on 8 September 2017, 2:51 pm EST

  • Posted 8 September 2017, 2:51 pm EST


    I am adding an unbound row into the grid control. And adding that row to the datasource using AddRowToDataSource.

    Let's say I have 3 rows in a grid by default and I am adding a row between row 2 and row 3. So the total rows becomes 4.

    Visually the sequence is correct but when I save the data, it seems that the unbound row gets added at the last position in datasource.

    Ideally it should be at position 3 and existing row which is there at position 3 should move to position 4.

    Please let me know how it is functioning.


  • Replied 8 September 2017, 2:51 pm EST


    I would like you to know that what you are seeing is the intended behavior of Spread, whenever a new row is added to a DataTable in the DataSet, it is always appended at the end. Similarly, the AddRowToDataSource method appends the new row to the end of the DataSource. The row parameter in the AddRowToDataSource specifies the row index of the row in the Spread which is to be added to the datasource.

    Hope it will help you. Please let me know if you have any queries further.


    Manpreet Kaur.

  • Replied 8 September 2017, 2:51 pm EST


    The data model keeps a mapping of data row index to model row index for each bound row.  This mapping starts out identical (data row index = model row index) but can change when unbound rows are added.  In that case, the mapping is no longer identical after the inserted unbound row index.   You can query this mapping with GetDataRowFromModelRow and GetModelRowFromDataRow.  It is not possible to rearrange the order of the data rows, and new rows are always appended to the end of the data source list.

Need extra support?

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

Learn More

Forum Channels