0
votes

I can't perform copy operations from my DataGrid to the clipboard. I want to allow the user to select some cells from the DataGrid and paste them wherever he wants.

When I try to select a cell in the grid by clicking on it with the mouse, nothing appears to happen. The cell/row does not change to highlighted, and copy (ctrl C) doesn't do anything.

Here is my DataGrid:

    <Grid Margin="2,2,2,2" Background="LightGray">
    <!--  Log  -->
    <Label Name="activityLogLabel"
           Height="28"
           Margin="15,5,0,0"
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Content="Activity log" />
    <Grid Width="500"
          Height="482"
          Margin="15,25,0,0"
          HorizontalAlignment="Left"
          VerticalAlignment="Top"
          Background="White">
        <DataGrid x:Name="log"
                  MaxHeight="Infinity"
                  AutoGenerateColumns="False"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  CanUserReorderColumns="False"
                  CanUserResizeColumns="True"
                  ClipboardCopyMode="ExcludeHeader"
                  ClipToBounds="True"
                  DataContext="{StaticResource LogViewModel}"
                  HeadersVisibility="None"
                  IsEnabled="true"
                  IsManipulationEnabled="True"
                  IsReadOnly="True"
                  ItemsSource="{Binding Path=LogData}"
                  RowHeight="NaN"
                  SelectionMode="Extended"
                  SelectionUnit="Cell">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Time, Mode=OneWay}" CanUserResize="False" />
                <DataGridTextColumn Binding="{Binding Text, Mode=OneWay}" CanUserResize="False">
                    <DataGridTextColumn.ElementStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="Foreground" Value="{Binding LogLevel, Mode=OneWay, Converter={StaticResource LogLevelConverter}, ConverterParameter=.}" />
                        </Style>
                    </DataGridTextColumn.ElementStyle>
                </DataGridTextColumn>
            </DataGrid.Columns>
        </DataGrid>

    </Grid>
1
don't know much about .Net but if you are copying different cells, how is the computer supposed to represent it internally? - Shaheer
@Shaheer I don't really care about the time field. It would be fine if I get all the data as a string, or just be able to get the data from the Text column - OSH
then probably the best idea i would suggest is bind an event for ctrl+c combination in that event handler check which cells are selected (if any) combine there value in a string ( comma separated ) and copy that string to clip board. ( i hope .Net has a method to do that ). - Shaheer

1 Answers

1
votes

Damn. I feed very stupid right now. I had an image (semi transparent) shown ON TOP of the data grid (to provide a water-mark with our log). When the user was trying to rows he was actually selecting the image...