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.
ADAdministrator Syncfusion Team March 3, 2003 02:46 PM
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.
TDThomas DomuratMarch 4, 2003 12:29 PM
Would there be a VB code example? I would greatly appreciate it if you could post that if one exists. Thanks.