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 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.
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
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.
Hi Mike!
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.
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.