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

DataBoundGrid throwing exception when pasting values

Hi, I am using Data bound grid. When I try to copy/paste rows into my grid, it throws some exception from grid base classes. You can reproduce this error in the FilterBarGrid sample. 1. Run 2 instances of the sample. 2. Highlight 3 or 4 rows (or some area with 3 cols/4 rows) and click Ctrl-C 3. Goto the second instance (which is executing from VS.NET, click in the last row (add new row) and hit Ctrl-V. 4. Notice the following exception in the output window. Can you please look into this. Thanks, - Reddy Additional information: Object reference not set to an instance of an object. Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.System.IndexOutOfRangeException: Index 91 is not non-negative and below total rows count. at System.Data.DataView.GetElement(Int32 index) at System.Data.DataView.System.Collections.IList.get_Item(Int32 recordIndex) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.Syncfusion.Windows.Forms.Grid.IGridModelDataProvider.SaveCellInfo(GridSaveCellInfoEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType, Boolean dontRaiseSaveCellInfoEvent, Boolean copyReferenceOnly) at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.ChangeCells(GridRangeInfo range, GridStyleInfo[] cellsInfo, StyleModifyType modifyType) at Syncfusion.Windows.Forms.Grid.GridModel.Syncfusion.Windows.Forms.Grid.IGridVolatileDataContainer.ChangeCell(Int32 rowIndex, Int32 colIndex, GridStyleInfo style) at Syncfusion.Windows.Forms.Grid.GridVolatileData.set_Item(Int32 rowIndex, Int32 colIndex, GridStyleInfo value) at Syncfusion.Windows.Forms.Grid.GridStyleInfoIdentity.OnStyleChanged(StyleInfoBase style, StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.OnStyleChanged(StyleInfoProperty sip) at Syncfusion.Styles.StyleInfoBase.SetValue(StyleInfoProperty sip, Object value) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.set_CellValue(Object value) at Syncfusion.Windows.Forms.Grid.GridCellModelBase.ApplyFormattedText(GridStyleInfo style, String text, Int32 textInfo) at Syncfusion.Windows.Forms.Grid.GridStyleInfo.ApplyFormattedText(String text, Int32 textInfo) at Syncfusion.Windows.Forms.Grid.GridModelTextDataExchange.PasteTextRowCol(Int32 rowIndex, Int32 colIndex, String text) at Syncfusion.Windows.Forms.Grid.GridModelDataBinder.DataBoundPaste(IDataObject iData, Int32 clipboardFlags, GridRangeInfoList rangeList, GridCutPasteEventArgs e) at Syncfusion.Windows.Forms.Grid.GridDataBoundGridModel.OnClipboardPaste(GridCutPasteEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelCutPaste.Paste() at Syncfusion.Windows.Forms.Grid.GridControlBase.OnKeyDown(KeyEventArgs e) at Syncfusion.Windows.Forms.Grid.GridDataBoundGrid.OnKeyDown(KeyEventArgs e) at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m) at Syncfusion.Windows.Forms.Grid.GridControlBase.ProcessKeyEventArgs(Message& m) at Syncfusion.Windows.Forms.Grid.GridControlBase.ProcessKeyPreview(Message& m) at System.Windows.Forms.Control.ProcessKeyMessage(Message& m) at Syncfusion.Windows.Forms.Grid.GridTextBoxControl.ProcessKeyMessage(Message& m) at System.Windows.Forms.Control.WmKeyChar(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.TextBoxBase.WndProc(Message& m) at System.Windows.Forms.RichTextBox.WndProc(Message& m) at Syncfusion.Windows.Forms.Grid.GridTextBoxControl.WndProc(Message& msg) catched at Syncfusion.Windows.Forms.Grid.GridTextBoxControl.WndProc(Message& msg) in :line 0

1 Reply

AD Administrator Syncfusion Team November 12, 2003 07:05 AM UTC

If you just want to avoid the error, you can subscribe to PasteCellText and cancel the paste if you are trying to paste beyond the populated grid. //subscribe to the event this.gridDataBoundGrid1.Model.PasteCellText += new GridPasteCellTextEventHandler(grid_PasteCellText); //the handler //the handler private void grid_PasteCellText(object sender, GridPasteCellTextEventArgs e) { if(e.RowIndex >= this.gridDataBoundGrid1.Model.RowCount) { e.Cancel = true; } } This avoids the complexity to trying to add rows to your datasource and pasteing over unique foreign keys, etc. But if you want to auto-append new rows, you can do so in Model.ClipboardPaste. Attached is a little sample. Exactly how you might do it, depends upon your datasource and how you want to avoid unique foreign keys trying to be pasted over. The little sampple does not have foreign keys...

Live Chat Icon For mobile
Up arrow icon