It is possible in ultrawinGrid, select one cell , performing Me.UltraGrid1.PerformAction(UltraGridAction.Copy), and then paste the value in multiselected cells?Does exist a buit-in feature? If i use Me.UltraGrid1.PerformAction(UltraGridAction.Paste) , the value is copied only in the last active cell. I'd like that the value is copied into all selected cells.Riccardo
Hi Riccardo,
There's nothing built-in to the grid to do this. But you could modify the grid's behavior using the BeforeMultiCellOperation event. Here's a very simple example of how you might go about it. This doesn't account for nulls or data type mismatches or other errors, it's just something I threw together very quickly. But it should point you in the right direction.
private void ultraGrid1_BeforeMultiCellOperation(object sender, BeforeMultiCellOperationEventArgs e) { UltraGrid grid = (UltraGrid)sender; if (e.Operation == MultiCellOperation.Paste) { if (e.Cells.ColumnCount == 1 && e.Cells.RowCount == 1) { object newValue = e.NewValues[e.Cells[0, 0]].Value; foreach (UltraGridCell cell in grid.Selected.Cells) { cell.Value = newValue; } e.Cancel = true; } } }
Mike (or others),
Just looking at this suggestion from a year or so back, and it almost fits our requirements here, but won't correctly supporting grids that are using embedded DateEditor and ComboEditor controls.
For these the NewValues collection is returning the display text from the first cell, rather than the underlying value (our combos have GUID keys underneath for example). And then setting this into cell.Value results in a cast error (string to GUID or string to DateTime).
Messed around with a few ideas, but can't spot any way to get the actual value that is about to be pasted.
Other ideas:
- Trying to set display text of each paste cell, which requires entering edit mode on every cell I think- Capturing the value as the copy action happens, but this is problematic because the editor control swallows a single cell action and the grid doesn't actually see it (only row or multi-cell copies)
Any tips on which direction I might head in, to get clean multi cell paste with these embedded editors?
Had a play and didn't have any luck with looking up the ValueList, but have got it working by entering edit mode and then setting SelText instead of Value.
Not as ideal because you see the screen flicker as each cell is activated and edited, but I've limited that to just certain editor types, and anything else like numeric cells continue to set Value as normal.
Thanks for the ideas!
Hi,
I think what you would probably have to do is find the matching item on the list for each cell.
How you do that depends on exactly what you are doing, so there's no single generic solution. If you are setting the ValueList property on the column, then you could get the ValueListResolved from the destination cell and the call the GetValue method on it and pass in the text. This will return the matching value on the list (if there is one) and you can set the cell's Value to that Value.
If you are using Editor or EditorControl instead of ValueList, then I think ValueList might still work, but I'm not sure. You might have to get the list from the Editor, instead.