简体   繁体   中英

Copy text of single cell to clipboard

My CurrentCellValue is always null.

I want to mark a row but also if I choose to copy ( Ctrl + C ) a cell I want that value to be copied, now I get the whole row.

<dxg:GridControl
    Name="GridControl"
    ColumnsSource="{Binding Columns}"
    ItemsSource="{Binding Orders}"
    ColumnGeneratorTemplate="{StaticResource ColumnTemplate}"
    AutoGenerateColumns="None"
    ColumnGeneratorStyle="{StaticResource CommonColumnStyle}"
    SelectedItems="{Binding SelectedOrders}"
    SelectionMode="Row"
    CustomSummary="GridControl_OnCustomSum"
    SelectionChanged="GridControl_OnSelectionChanged"       
    CopyingToClipboard="GridControl_OnCopyingToClipboard">
private void GridControl_OnCopyingToClipboard(object sender, CopyingToClipboardEventArgs e)
{
    Clipboard.Clear();
    Clipboard.SetText(GetRowData());
    e.Handled = true;
}

private string GetRowData()
{
    return GridControl.CurrentCellValue.ToString();
}

SOLUTION:

 <dxg:TableView Name="GridTableView" NavigationStyle="Cell" />

Now I have a value in CurrentCellValue

  1. If there's only one cell that you may wish to copy text from:

You can add "SelectedItem" Binding to your GridControl, and in "GridControl_OnCopyingToClipboard" try to find inside the selectedItem the relevant text that you want to copy.

  1. If there're several cells in a row that you may wish to copy from them, and it really matters which one you clicked on inside same row, then you might want to reconsider this line: SelectionMode="Row"... And change "Row" to "Cell", then again add "SelectedItem" Binding as I mentioned above, and get the text from it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM