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.
I know this is a very old post. I'm on 14.1. Is there a way to do this now?
If not built-in, is there a way to split the values that are to be pasted? I want to paste the available records and then add the remaining records. ClipboardPastingEventArgs.Values doesn't have a setter, so I can't modify it that way and then just run both commands.
Hello Jon,
Currently the approach Andrew explained seems to be the best one for achieving the functionality you want, because the functionality you want is still not built in. You can suggest this as new product idea for future versions (or vote for existing ones) at http://ideas.infragistics.com.
There are many benefits to submitting an product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
Steps to create your idea:
The Product Idea site puts you in the driver’s seat and allows you to track the progress of your ideas at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Thank you for contacting Infragistics.
I found this forum post that does what I was looking for.
http://es.infragistics.com/community/forums/p/53729/278971.aspx#278971
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.