I am exporting Xamdatagrid to Excel. Changing the value of cells and adding new rows. I just see paste back happening from Excel to XamDataGrid only for the rows in the grid. I also want new rows from Excel pasted to Grid. Is this possible?
I have the same issue. When copying from Excel i do not want to modify existing records. I would like to add new Records and fill these with the values copied from Excel.
I tried intercepting the clipboardpasting event but the event contains only the records selected from the grid.
How can i Solve this problem?
gasdausps said:When copying from Excel i do not want to modify existing records. I would like to add new Records and fill these with the values copied from Excel.
The only time that new records are generated is when the addrecord or one of its cells is active (and you are not in edit mode) and you paste. In that case a new record will be created for each item that is in the clipboard data. If focus wasn't in the addrecord and you still wanted to do this then you would probably have to handle the clipboardpasting event, set e.cancel to true so it doesn't paste into the existing records (assuming the record in the args is not an add record) and asynchronously start another paste operation. E.g.
private void grid_ClipboardPasting(object sender, Infragistics.Windows.DataPresenter.Events.ClipboardPastingEventArgs e){ DataRecord targetRecord = e.GetTargetRecord(0); if (!targetRecord.IsAddRecord) // yes insert records { // cancel the paste at this location and asynchronously // start another paste operation after we activate the // add record at this location e.Cancel = true; DataPresenterBase dp = targetRecord.DataPresenter; // clear the selection so the grid won't use those as the target dp.SelectedItems.Records.Clear(); dp.SelectedItems.Cells.Clear(); // activte the add record targetRecord = targetRecord.RecordManager.CurrentAddRecord; if (null != targetRecord) { targetRecord.IsActive = true; Cell cell = targetRecord.Cells[e.GetTargetField(0)]; if (null != cell) cell.IsActive = true; DispatcherOperationCallback callback = delegate(object param) { ((DataPresenterBase)param).ExecuteCommand(DataPresenterCommands.Paste); return null; }; dp.Dispatcher.BeginInvoke(DispatcherPriority.Normal, callback, dp); } }}
if (!targetRecord.IsAddRecord) // yes insert records { // cancel the paste at this location and asynchronously // start another paste operation after we activate the // add record at this location e.Cancel = true; DataPresenterBase dp = targetRecord.DataPresenter;
// clear the selection so the grid won't use those as the target dp.SelectedItems.Records.Clear(); dp.SelectedItems.Cells.Clear();
// activte the add record targetRecord = targetRecord.RecordManager.CurrentAddRecord;
if (null != targetRecord) { targetRecord.IsActive = true;
Cell cell = targetRecord.Cells[e.GetTargetField(0)];
if (null != cell) cell.IsActive = true;
DispatcherOperationCallback callback = delegate(object param) { ((DataPresenterBase)param).ExecuteCommand(DataPresenterCommands.Paste); return null; };
dp.Dispatcher.BeginInvoke(DispatcherPriority.Normal, callback, dp); } }}
Since the records in view are going to change you might also consider giving the user a messagebox prompt.