I'm experiencing some interesting behavior on my application. I have a grid where I've allowed multi cell operations.
When I paste something on a selected cell using the ctrl+v keys, everything works as it should. However, if i try to simulate the behavior by using the following code.
private void pasteTSB_Click(object sender, EventArgs e) { ultraGrid1.PerformAction(UltraGridAction.Paste,false,false); }
The AfterPerformAction event is not raised. Any clues as to what may be happening?
I think the grid is not in the correct state to accept the Paste and then the After event is also not raised.
How can I verify what the right state is before pasting? how do i put the grid into the right state? Have in mind that the paste action is happening what is not happening is the after perform action event.
Here is what i do in pseudocode.
Grid.PerformAction(Paste);
Grid_BeforeMultiCellOperation(...){ SomeFlag = true; //Gets called when using ctrl+v on a selected cell. //Gets called when using performaction(Paste);}
Grid_AfterCellUpdate(...){ if(SomeFlag) DoSomething(...); //Gets called when using ctrl+v on a selected cell. //Gets called when using performaction(Paste);}
Grid_AfterPerformOperation(...){ SomeFlag = false; //Gets called when using ctrl+v on a selected cell. //DOES NOT get called when using performaction(Paste); <== why?}
Some flag is not set correctly when I use the performaction(paste).
There are two different kinds of pasting here. If a cell in the grid is in edit mode, then the cell itself handles this. This is a single cell operation and has nothing to do with the AllowMultiCellOperation or PerformMultiCellOperation functionality. Those are for pasting multiple cells, obviously. :)
So if you want to paste into a single cell, you should be setting the grid.ActiveCell.SelectedText, just as you would for a TextBox or other control.
I have been able to work something out, by hacking around the issue. But here is the deal, I was looking for an event that was never there (i'm using version v8.1 of netadvantage).
There is a BeforeMultiCellOperation, but there is no AfterMultiCellOperation. So since i could not find the pair i started using AfterPerformAction(Action.Paste) as that missing event.
However because the afterperformaction event gets raised when pasting through keyboard shortcut but, not when programmatically calling grid.performaction(Action.Paste); I was encountering holes in my logic.
My hack is ugly, i was basically trying to replicate the keyboard shortcut behavior. And the SendKeys class was having trouble on my 64bit operating system. What I did is subclass from the ultragrid class and expose the protected internal PerformKeyAction(Action.Paste) which is what gets called when pressing the keyboard shortcut.
Someone please enlighten me if there is some better answer.
Check if you have allowed pasting as multicelloperation
e.Layout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;