Hello,
I am trying to copy/paste in UltraGrid (just usual Windows Ctrl-C/Ctrl-V) but it doesnt look straightforward.
I have used the below property to allow copy/paste. Still yet, its complaining the contents is more than current capacity.
Any workaround to resolve this, as we have requirement to enter huge values in the grid and this will be typically copied from the excel spreadsheet.
this.ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.Copy | AllowMultiCellOperation.Paste;
What's the problem, exactly? What is the error message you are getting? Where are you copying from and what is selected in the grid when you are pasting?
Right,
The problem is that, when I have ultragrid - single column with date values and need to have functionality for the user to copy list of dates from excel spreadsheet to this column. I can able to paste just one row but if the copy content is more than 1 row, then I see an error:
Error performing paste operation. Contents being paste have more rows than whats available starting from the anchor cell. Paste contents have 8 rows where as the available rows starting from the anchor cell are 1.
Can you suggest any solution ?
I tried handling BeforeMultiCellOperation event, but it appears the number of cells that were copied from Excel spreadsheet is not passed through this event handler, as I couldn't get exactly how many number of rows to add from e.Cells.RowsCount.
Can you suggest, how exactly BeforeMultiCellOperation can be handled in this case?
If this is not possible through UltraGrid, is there anyother workaround using other controls?
Hi,
I tried it out and it looks like the error occurs before the BeforeMultiCellOperation event fires, so my suggestion won't work.
You might be able to use the grid's Error event, instead. It's going to be pretty tricky, though. I got this working in a very simple case and I have posted the code here, but please note that this code is not complete.
void ultraGrid1_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e) { // Is this an error from a Paste operation? if (e.MultiCellOperationErrorInfo != null && e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste) { // Is there an Exception? InvalidOperationException exception = e.MultiCellOperationErrorInfo.Exception as InvalidOperationException; if (exception != null) { // IS this an exception because there aren't enough selected rows? string exceptionStart = "Contents being pasted have more rows than what's available starting from the anchor cell. Paste contents have "; string exceptionMessage = exception.Message; if (exceptionMessage.StartsWith(exceptionStart)) { // Parse the exception message to determine the number of rows that we would need in // or to successfully complete the Paste operation. exceptionMessage = exceptionMessage.Substring(exceptionStart.Length); int rowsIndex = exceptionMessage.IndexOf(" rows"); if (rowsIndex == -1) return; exceptionMessage = exceptionMessage.Substring(0, rowsIndex); int rowCountNeeded = int.Parse(exceptionMessage); UltraGrid grid = (UltraGrid)sender; // Sort the selected rows in visible order to make the logic simpler. grid.Selected.Rows.Sort(); // Add new rows to the grid and move them into position under the last selected row and // select these rows. while (grid.Selected.Rows.Count < rowCountNeeded) { UltraGridRow lastSelectedRow = grid.Selected.Rows[this.ultraGrid1.Selected.Rows.Count - 1]; UltraGridRow newRow = grid.DisplayLayout.Bands[0].AddNew(); newRow.ParentCollection.Move(newRow, lastSelectedRow.Index + 1); grid.Selected.Rows.Add(newRow); } // The current operation has failed, but now we have new rows to paste into so // cancel the error message and do another paste. e.Cancel = true; grid.PerformAction(UltraGridAction.Paste); } } } }
This code won't handle hierarchical data.
Also, the exception message could be localized, so the parsing here would not work in such a case.
Not sure, why you mentioned about the error before BeforeMultiCellOperation. But I have found a workaround from one the KB articles which works by:
1. Copying the content from Clipboard.Text
2. Parsing no. of lines
3. Creating the same rows/columns &
4. Insert into the Grid.
Anywyas, thanks for the suggestions.
Would be good idea, if you can request your team to provide some simple solution for UltraGrid paste especially there are loads of simple user request to copy it from the excel.
I'm trying to copy a column of cells from Excel but I already have all the rows that I need in the grid.
I'm not adding any rows to the grid.
Is there something that does that.
Hi rhd,
I'm afraid I do not understand your question. If you want to copy and paste from Excel into the WinGrid, you just have to turn on AllowMultiCellOperation on the Override to allow pasting.
Thanks I got it working.
I am checking about the progress of this issue. Please let me know If you need any further assistance on this.
You will have this ability just by doing what Mike said:
If you want to copy and paste from Excel into the WinGrid, you just have to turn on AllowMultiCellOperation on the Override to allow pasting.
Do you have the example in code so I can see how you did it?
Thanks.
Yes, you can. I did it the other way just for the video sample.