Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
Main menu edit items and short cut keys questions
posted

hi all,

I have a Windows form with a main menu (UltraToolbarsManager).  This is a regular Windows main menu, not a ribbon.   On this menu I have standard edit menu items, i.e, Copy, Paste, Cut...     On the form, I have 3 grids, 1 tree, and some textboxes.   I want to use this set of edit menu items to control the edit functions of all controls on the form.     For example, I should be able to copy text from any text field, like a textbox or a grid cell by using the same Copy button from the main menu.      Also I should be able to do the same with Ctrl+C.     Also I should be able to copy and paste tree nodes.

What's the most efficient way to implement this?  

I've read this article: http://help.infragistics.com/Help/NetAdvantage/NET/2008.2/CLR2.0/html/WinGrid_Creating_an_Edit_Menu_with_Clipboard_Operations_for_WinGrid.html

but having several issues:

1. This sample uses the Edit menu items to control one grid. What if I have many controls on the form that I need to edit?

2. Me.ultraGrid1.PerformAction(UltraGridAction.DeleteCells)   doesn't work.

3. this.ultraGrid1.PerformAction(UltraGridAction.Cut)    only works after the cell loses focus

4. If you copy the text from a grid cell then paste it to a textbox outside of the grid, only the column name is pasted. If paste to Notepad, both column name and text are pasted.    The correct behavior is that only the text should be pasted.

5. If I add ShortCut CtrlC to the Copy menu item,   CtrlC no longers works on other controls outside of the grid.

please help. Basically I need something like the MS Word Edit menu items that work on all controls

thanks in advance.

Tony.

  • 469350
    Suggested Answer
    Offline posted

    Hi Tony,

    tony_easyrider said:
    2. Me.ultraGrid1.PerformAction(UltraGridAction.DeleteCells)   doesn't work.

    I tried this out and it works fine for me. In order for this to have any effect, there are a couple of confitions that must be met.

    First, the AllowMultiCellOperation property has to be set to all Deleting.

    Second, the grid must have some cells selected. Selecting a Row will not do it, nor will selecting a column. Also, there's a difference between selecting a cell and selecting text within that cell. The cell itself must be selected for this to work.

    tony_easyrider said:
    3. this.ultraGrid1.PerformAction(UltraGridAction.Cut)    only works after the cell loses focus

    I tested this out and it also works fine for me, but it is subject to essentially the same conditions as DeleteCells.

    When a Cell is in edit mode, you need to deal with the text of that cell, you can't cut, copy, paste, or delete using PerformAction. You will probably need to operate on the grid's ActiveCell using the SelText, SelLength, and SelStart properties of the cell.

    tony_easyrider said:
    4. If you copy the text from a grid cell then paste it to a textbox outside of the grid, only the column name is pasted. If paste to Notepad, both column name and text are pasted.    The correct behavior is that only the text should be pasted.

    My guess is that your TextBox doesn't support multiline text. Make sure Multiline is set to true on the TextBox.

  • 44743
    Suggested Answer
    posted

    You can use similar code as in the article, but since you have multiple controls, you will have to use slightly different code based on the ActiveControl of the Form.

    I would recommend making a helper method on your Form which examines the ActiveControl of the Form. This method should return a Control instance. It can be called something like GetEditOperationControl. If the ActiveControl is one of the controls for which you want to handle the edit operations, return it. Otherwise, check it's Parent control. if the Parent Control is your Form, return null. Otherwise, recursively call back into the helper method with the Parent Control and return that call's return value.

    Then make a helper method to handle the edit operation for each one of your edit controls. Something like HandleGridEditOperation(UltraGrid grid, ... editOperationID), HandleTreeEditOperation(UltraTree tree, ... editOperationID), etc. In the ToolClick code for the edit tools, call GetEditOperationControl. If it returns null, do nothing. If it returns an UltraGrid instance, pass it into HandleGridEditOperation, ... By the way, in your HandleGridEditOperation method, you would use the code from the article and replace all references to this.utlraGrid1 with references to the grid passed into the method.

    tony_easyrider said:
    1. This sample uses the Edit menu items to control one grid. What if I have many controls on the form that I need to edit?

    This will be taken care of by using the method described above.

    tony_easyrider said:
    5. If I add ShortCut CtrlC to the Copy menu item,   CtrlC no longers works on other controls outside of the grid.

    If you also handle the UltraToolbarsManager.BeforeShortcutKeyProcessed event, you can call GetEditOperationControl. If the method returns null, set e.Cancel to True on the event args. This will prevent the processing of the shortcut and allow the active control on the Form to process the command as it normally would have.

    As for your other questions, I am not as familiar with the grid, so I will forward this post to another developer who is more familiar.