I am using a readonly grid with
ultraGrid1.DisplayLayout.Override.CellClickAction = CellClickAction.RowSelect;
However if the user double clicks a cell I want them to be able to copy the cell. I have been trying to use different functions in the DoubleClickCell event, but cant figure out the right combination. When I try setting the clickaction to cellselect in the doubleclick event it isnt activated until the next cell click.
Hi,
So, just to be clear, you want the user to double-click on a cell and copy only the contents of that one cell to the clipboard? Is that right?
How are you copying the data to the clipboard? I'm guessing you probably tried to use PerformAction or PerformMultiCellOperation, but these probably will not work, since these simulate user actions and the user cannot select a cell.
What I would do is simply use the Clipboard object and call SetValue to put the value of the cell onto the clipboard yourself. This is easy, since it's just one cell and you don't have to worry about separators or complex data.
Hi sorry for not being more clear. I want a double click action to highlight just one cell rather than the row
Okay, that makes sense. So I'm guessing you are handling the DoubleClickCell event and selecting the cell. This actually works and selects the cell, but then it happens after the second MouseDown message and then the MouseUp fires and the row gets re-selected.
So what you have to do is introduce a delay so that the selection of the cell doesn't occur until the grid has completely processed the mouse messages.
Here's some sample code that seems to work as long as you double-click reasonably fast. It might not work if you click once and then click and hold the mouse before releasing. But that's kind've a weird case, anyway, so I don't think it's a problem.
private void ultraGrid1_DoubleClickCell(object sender, DoubleClickCellEventArgs e) { UltraGrid grid = (UltraGrid)sender; grid.BeginInvoke(new CellDelegate(this.SelectCell), new object[] {e.Cell}); } private delegate void CellDelegate(UltraGridCell cell); private void SelectCell(UltraGridCell cell) { cell.Selected = true; }