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!
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,
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:
Let me know if you have any questions.