Can you explain what the Infragistics Grid Copy/Paste from Excel feature does? Can I do copy and paste of highlighted or selected columns or rows within the Ultra Win grid like Excel ?
Hi,
I'm pretty sure that columns are not supported, but you can copy and paste selected cells or rows to and from Excel UltraWinGrid. You can also copy and paste within the grid or from one grid to another.
There's a sample included with NetAdvantage in the WinGrid Samples Explorer.
To enable this feature, use the AllowMultiCellOperation property.
I found this sample and got it working in one of my projects. However, when i try to paste in new rows at the bottom of my grid that allows new rows it just throws an error saying there are more rows to paste then exist in the grid. Is there a property I can set that will allow paste in the excel rows as new rows in the grid? If not can you think of a way around this problem?
Thanks a lot,
Jesse
Ramsey,
I tested my sample with your logic in the Error event. In C# this is:
void ultraGrid1_Error(object sender, ErrorEventArgs e){ if (e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste) { e.Cancel = true; e.MultiCellOperationErrorInfo.Action = MultiCellOperationErrorInfo.ErrorAction.Continue; }}
The BeforePerformAction event fires before the Error event and then only if there is an error does the Error event fire. I verified this by removing the logic to add the new rows to the data source in the BeforePerformAction when I was testing the sample.
As such if you are getting to the Error event, then I would expect the logic in the BeforePerformAction event handler may be incorrect in your application. Do you have an example that I can test on my end?
Let me know if you have any questions with this matter.
Hmm. The BeforePerformAction event never fires. I took the sample, translated it to VB and ran the debugger with a break point on the first line in the BeforePerformAction event handler where it tests to see if the Action is a paste action. The breakpoint in the BeforePerformAction event is not hit but the error event is raised.
I also recreated the BeforePerformAction event handler with no code in it and put a breakpoint on the declaration. That breakpoint is not reached either but again the Error event handler in that module is reached.
I appreciate your help...I'm lost.
If you used utility to translate the code, then it may be that the Handles keyword is missing from the event and this may need to be added. Please verify that the Handles keyword is on the event handler.
Thanks. No, I translated the code myself. I can do either language. I even commented out the whole handler that I had placed your code in and allowed the IDE to create the declaration again. I put a breakpoint on the declaration of the handler and on the error handler. The error handler was hit but the BeforePerformAction was not. For the sake of discussion though, here is the declaration:
UltraGrid1.BeforePerformAction
What is the error that you are getting in the error handler? Are you able to paste the same content into the sample that I provided?
If there is a difference in behavior between your application and my sample, then there may be different properties set on the grid. In my sample the only relevant properties that I have set are set in the InitializeLayout event handler:
void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e){ e.Layout.Override.CellClickAction = CellClickAction.CellSelect; e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All; }
}
What happens if you set these same properties in your application? If there is still a difference in behavior, let me know what else you have set and I can modify my sample and test again. Alternatively if you have a sample that reproduces the issue, I could debug that.
Hello,
I have followed the steps provided and I wasn't able to reproduce the behavior with the attached sample. Are you able to reproduce the behavior with the attached sample? If so, what are the exact steps that you took and what is the value of e.ErrorText in the Error event?
Hi Allan,
Thank you for your response. I think Ramsey has explained but I will recap. Take the C# sample that comes with NetAdvantage 2010.3 and add the event handler for BeforeMultiCellOperation() by double clicking the event in the propeties window for the frmCutCopyPaste form. Add a breakpoint. Then take the code you provide above for UltraGrid1_Error and replace the code in the sample. Set a breakpoint on the first line of code. Run the sample app and and select multiple rows. click Copy button. Scroll down and highlight the last row aand click the Paste button. You will notice that you hit the breakpoint in UltraGrid1_Error() first. If you continue through your code you will notice that you never hit the breakpoint in BeforeMultiCellOperation(). So the question is how do we get past the error in order to add rows to the grid and paste the contents of the clipboard?
I am still working with Ramsey regarding the pasting and adding the rows. On my end I haven't yet seen a case where the Error event was fired first. I have seen issues with the logic for adding rows where the rows wouldn't be added and then the error event would fire after that. Do you have any example that shows the error event firing first that I could debug with?
Sorry, I was referring to the previous thread. I am trying to paste multiple row into a grid. Allen had posted some sample code that would parse the clipboard and add new rows. The problem is that the Grid error event seems to be thrown before the BeforeMultiCellOperation event ( where his code resides). He created case CAS-64104-5BFMPMP to help resolve the issue. I seem to be seeing the same thing and wondered what the resolution was.
To what issue are you referring? There no issues described here, it's just a question. And the answer is yes. AllowMultiCellOperation allows you to copy and paste cells and/or rows in the grid. You can do this within the same grid, from one grid to another, from the grid to Excel and vice versa.