We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Adding rows by Copy n'Paste from Excel

Would like to add rows to a data-bound grid by pasting rows from Excel. The underlying table has an identity primary key, which I would NOT copy a value into this field. Copy and paste works fine if the source and destination ranges are the same. When I try add a range of values, I get: "An unhandled exception of type 'System.IndexOutOfRangeException' occured in system.data.dll Additioanl information: Index 1 is not non-negative and below total rows count." Is there sample of code of how this can be done? I would like the ability to create multiple rows at one time by copying from Excel.

2 Replies

AD Administrator Syncfusion Team March 3, 2003 07:46 PM UTC

Hi Tom, you need to handle the GridModel.ClipboardPaste event. You can subscribe to it via dataBoundGrid.Model.ClipboardPaste. I am attaching some source code from the grid library that might be of use. What you will need to do is check if you need to add rows, and then call AddNew, add the data for the row and then EndEdit for every new row that needs to be added to the datasource. You could also just add the data directly to the datasource and then just refresh the grid. In this case calling SuspendBinding/ResumeBinding and/or BeginUpdate/EndUpdate might be of use. In a future version I would like to have this an option so that the grid automatically detects when it needs to add rows and act accordingly but for now you have to code this yourself. Let me know if you run into trouble. Stefan

TD Thomas Domurat March 4, 2003 05:29 PM UTC

Would there be a VB code example? I would greatly appreciate it if you could post that if one exists. Thanks.

Live Chat Icon For mobile
Up arrow icon