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

Exception pasting rows

I have a data bound grid. I use GridModelCutPaste.Paste to paste a row I just copied. I set EnableAddNew to true. If I try to paste to the last row (the fake one used to add record), I get an exception. If I paste to a real row, it works fine. Here''s the stack trace: Object reference not set to an instance of an object. 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.GridComboBoxCellModel.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.GridModel.RaiseClipboardPaste(GridCutPasteEventArgs e) at Syncfusion.Windows.Forms.Grid.GridModelCutPaste.Paste() at SDB.viewRule.HandleCommand(String cmd, Object arg) at SDB.cmdDispatcher.DispatchCommand(String cmd, Object arg)

1 Reply

AD Administrator Syncfusion Team April 22, 2005 05:15 PM UTC

If you want to append rows dusing a paste, you will have to handle this your self. One way is to subscribe to the PasteCellText and add the row there is needed.
//subscribe to the event
this.gridDataBoundGrid1.Model.PasteCellText += new GridPasteCellTextEventHandler(Model_PasteCellText);

//the handler
private void Model_PasteCellText(object sender, GridPasteCellTextEventArgs e)
{
	if(e.ColIndex > this.gridDataBoundGrid1.Model.ColCount)
		e.Cancel = true;
	else if(e.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
	{
		CurrencyManager cm = this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource, 
			                                    this.gridDataBoundGrid1.DataMember] as CurrencyManager;
		cm.AddNew();
	}
	else if(e.RowIndex >= this.gridDataBoundGrid1.Model.RowCount)
		e.Cancel = true;
}

Loader.
Live Chat Icon For mobile
Up arrow icon