Hi!
I need to allow copy/paste of a row in a wingrid. The problem is that I have 2 cells that are read-only. So when I paste the row, I received an error asking me to continue to copy in the read-only cell or cancel. If I click OK then everything works fine. My question is How can I deactivate this message to always paste (with copy cell content in read-only cells) without warnings and message boxes ?
I looked in the WinGrid Error event and found MultiCellOperationErrorInfo object, but I didn't find the way to correct this behavior.
Best regards,
Benoit
Hi Benoit,
I think you should be able to achieve what you want with something like this:
private void ultraGrid1_Error(object sender, Infragistics.Win.UltraWinGrid.ErrorEventArgs e) { if (e.ErrorType == ErrorType.MultiCellOperation) { if (e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste && e.MultiCellOperationErrorInfo.CanContinueWithRemainingCells) { e.MultiCellOperationErrorInfo.Action = MultiCellOperationErrorInfo.ErrorAction.Continue; e.Cancel = true; } } }
Hi Mike!
It works great. Thanks. But I still have a problem. I have cells that contains decimal numbers with a display format (to see them as money) and a mask input and these cells do not paste correctly. After paste, the cells contains 0,00$ instead of the amount. Can you explain me why I have this problem ?
I have another decimal number that its display format is percent and the paste works.
Hi Mike,
I downloaded the latest service release (10.3.20103.2094) and it still doesn't work. The cell with a format (format=c) is not copied successfully.
I just tested this out in a small sample project an I also get an error. It looks like the dollar sign causes a problem with converting the string into a Decimal.
This seems like a bug to me and I am going to forward this thread over to Infragistics Developer support so they can create a case for you and write this up for developer review.
In the mean time, you can work around this issue by stripping out the dollar sign (or any currency symbol) from the value when pasting.
private void ultraGrid1_BeforeMultiCellOperation(object sender, BeforeMultiCellOperationEventArgs e) { if (e.Operation == MultiCellOperation.Paste) { foreach (UltraGridCell cell in e.Cells) { UltraGridColumn column = cell.Column; if (column.DataType == typeof(decimal) && column.Format == "c") { MultiCellOperationInfo.CellValueHolder info = e.NewValues[cell]; info.Value = info.Value.ToString().Replace(Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencySymbol, ""); } } } }
You could do the same thing when Copying, of course, but I think it makes more sense to handle this on the paste, because if you paste the data into NotePad or something, you probably want the currency symbol to be there.
your solution works but i will need a more complete solution because users can set their cell format as they wish. So it is possible that they use something else than "c" format. Then you code will not work. I will use it for the moment but I will wait for a bug fix that works for any cell format used.
Thank you very much for your help and your fast answer.
There is no way that the grid can account for every possible format here. The way Format works is that the grid takes the Value of the cell and calls it's ToString method and passes in the format.
But... there is no way in DotNet to reverse this process. You cannot get the original value back from the string. The workaround I listed here strips out the currency symbol, which is a pretty simple and obvious thing to do. But if your users are choosing a format that has other non-numeric characters in it, the only way to do with that would be to strip them all out and hope that what remains is a valid decimal value.
I understand the problem. So the bug fix that you will deliver to us will cover the case of Format = c on ly? I mean that you will develop something like the workaround that you give me and put in the ultragrid code instead of coding myself ? So I won't need to use your workaround ?
thanks
it should be a great idea if the copy/paste works with the value instead of the the display text in this case. It should respond to all my copy/paste problems.
I can't say for sure what, if any, fix we will come up with.
Perhaps I am wrong and there is another way we can handle this in the grid. We may be able to recognize this specific case and copy/paste the value of the cell instead of the display text. In which case, it will work as long as you are copying from a WinGrid and pasting to a WinGrid.
Developer Support will create a case for you and let you know when this is resolved.