Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / Read only grid, select single cell, right click to copy contents

Read only grid, select single cell, right click to copy contents

New Discussion
Nicholas Hunter
Nicholas Hunter asked on Aug 28, 2018 11:25 PM

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!

Sign In to post a reply

Replies

  • 0
    Alan Halama
    Alan Halama answered on Aug 23, 2018 4:58 PM

    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.

    • 0
      Nicholas Hunter
      Nicholas Hunter answered on Aug 27, 2018 8:52 PM

      Thanks, Alan! That's very helpful.

      I am setting the properties in the UltraGrid1 InitializeLayout handler

      Private Sub UltraGrid1_InitializeLayout(sender As Object, e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles UltraGrid1.InitializeLayout

      With e.Layout

      .GroupByBox.Hidden = True

      With .Override
      .SelectTypeCell = SelectType.Single
      .SelectTypeRow = SelectType.None
      .CellClickAction = CellClickAction.CellSelect
      .AllowUpdate = Infragistics.Win.DefaultableBoolean.False
      .AllowMultiCellOperations = AllowMultiCellOperation.Copy
      End With

      End With

      End Sub

      But the "single cell select" mode doesn't seem to take. The entire row appears to be selected, and when I copy & paste, data from the entire row is pasted,

      • 0
        Alan Halama
        Alan Halama answered on Aug 28, 2018 12:50 AM

        Nicholas,

        If it was just the appearance of the grid, I would think that you might be looking at the activation of the row which would still happen when selecting only a single cell.  As the values for the entire row are being pasted, I would assume that somehow the entire row is being selected in your grid though with the code provided I wouldn't expect that to happen.  Are you able to reproduce the behavior with the same code in an isolated sample that you could provide for me to debug to see what is happening.  I did test the individual settings when I first responded though I didn't get the behavior you are describing.

      • 0
        Nicholas Hunter
        Nicholas Hunter answered on Aug 28, 2018 11:25 PM

        D'oh! A piece of code I copied and pasted into the grid ClickCell event handler to implement the context menu was selecting the row. Everything works great now. Thanks again, Alan.

  • 0
    Nicholas Hunter
    Nicholas Hunter answered on Aug 28, 2018 4:47 PM

    Thanks, Mike. How do I turn off the default ActiveCellAppearance and ActiveRowAppearance in code?

  • 0
    Mike Saltzman
    Mike Saltzman answered on Aug 28, 2018 9:15 PM

            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                var layout = e.Layout;
                var ov = layout.Override;
    
                ov.ActiveCellAppearance.Reset();
                ov.ActiveRowAppearance.Reset();
            }

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Nicholas Hunter
Favorites
0
Replies
6
Created On
Aug 28, 2018
Last Post
7 years, 6 months ago

Suggested Discussions

Created by

Created on

Aug 28, 2018 11:25 PM

Last activity on

Feb 20, 2026 11:46 AM