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!
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:
Let me know if you have any questions.
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
.GroupByBox.Hidden = True
With .Override .SelectTypeCell = SelectType.Single .SelectTypeRow = SelectType.None .CellClickAction = CellClickAction.CellSelect .AllowUpdate = Infragistics.Win.DefaultableBoolean.False .AllowMultiCellOperations = AllowMultiCellOperation.Copy End With
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,
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.
You might want to turn off the default ActiveCellAppearance and ActiveRowAppearance, anyway. Just to avoid confusion:
Thanks, Mike. How do I turn off the default ActiveCellAppearance and ActiveRowAppearance in code?