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
15
Read only grid, select single cell, right click to copy contents
posted

I am a new user of UltraGrid and I find all the configuration option a little overwhelming.

I would like to create a read only grid. I would like the user to be able to select only a single cell at any time, and I would like to display a pop up menu to allow the user to copy the contents of the selected cell to the clipboard on right click.

Any help would be appreciated. TIA!

Parents
  • 22852
    Verified Answer
    Offline posted

    Nicholas,

    For copying and pasting, is there a reason why you only want to allow single selection rather than allowing the user to select multiple cells?

    If you really want single selection, you can set SelectTypeCell to Single and SelectTypeRow to None:

    this.ultraGrid1.DisplayLayout.Override.SelectTypeCell = SelectType.Single;
    this.ultraGrid1.DisplayLayout.Override.SelectTypeRow = SelectType.None;

    To have a cell be selected on mouse click, set the CellClickAction to CellSelect:

    this.ultraGrid1.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect;

    Note that if you don't set this to CellSelect the default is to enter edit mode and the editor will already provide a context menu to copy the value.  If you do this you would also want to set AllowUpdate to false to prevent updates from being made to the data:

    this.ultraGrid1.DisplayLayout.Override.AllowUpdate = DefaultableBoolean.False;

    For the copy and paste, you can set AllowMultiCellOperations to Copy to allow copying the selection with CTRL+C when a cell (or multiple) is selected.

    this.ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.Copy;

    If you don't use the editors, you will need to add your own context menu to the grid to get a copy option and you can refer to Using the WinGrid ClickCell Event to Show a Context Menu for details on showing a context menu.  If the cell is selected when the context menu is shown, you can use the PerformAction method of the grid to have the grid copy the cell value to the clipboard:

    this.ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.Copy;

    Let me know if you have any questions.

Reply Children