This is a migrated thread and some comments may be shown as answers.

Paste issues with GridView

5 Answers 265 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Louis
Top achievements
Rank 1
Louis asked on 04 Oct 2013, 09:49 PM
I'm trying to implement paste functionality into my GridView, but have run into 2 issues.

First, even if the Grid is set with SelectionUnit="FullRow" SelectionMode="Single", after a paste occurs the top row where the data was pasted remains selected. I can then select another row, ending up with multiple-rows selected. Subsequent pastes start at the top-most selected row, even if it's not the most recently selected row. Therefore, in addition to a very strange display (with multiple rows selected and no apparent way to unselect them), you can never paste data into rows below where you have previously pasted data.

The second issue is that the InsertNewRows value of GridViewClipboardPasteMode no longer appears to be present, such that pasting data when not enough rows exist to accommodate truncates the paste.

For reference, the options I'm using are:

       <telerik:RadGridView Grid.Row="0"  x:Name="HistoricalGridView" AutoGenerateColumns="False" ItemsSource="{Binding Path=HistoricalData}" 
                                 IsFilteringAllowed="False" ShowGroupPanel="False" CanUserSortColumns="False" 
                              ClipboardPasteMode="OverwriteWithEmptyValues,Cells" SelectionUnit="FullRow" SelectionMode="Single" >

Thanks for your help on these.

Louis

5 Answers, 1 is accepted

Sort by
0
Vera
Telerik team
answered on 09 Oct 2013, 12:24 PM
Hi Louis,

I tried to reproduce the issues you reported but to no avail. Attached you can find the project used for the test. Are you able to get the problems on it? Could you also specify the version of RadControls for WPF you are currently using?

Regards,
Vera
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Louis
Top achievements
Rank 1
answered on 09 Oct 2013, 04:35 PM
Hi Vera, thank you very much for the response, and the sample project. Indeed it did not exhibit the problems, so I tried isolating the difference causing the problem to manifest. After many unsuccessful attempts, I finally narrowed it down to the object supplying the data. It seems that if the objects being provided by the ItemsSource binding are structs rather than classes, both of the problems I described manifest themselves. I know GenericDataPointBindings solve this problem for ChartView; is there a similar work-around for this in GridView?

Here's a very simple code sample that you can use to recreate the problem (it exhibits it even with the dlls you supplied in your project):

XAML:
<Window x:Class="CutPaste.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <telerik:RadGridView Grid.Row="0"  x:Name="HistoricalGridView" AutoGenerateColumns="False" ItemsSource="{Binding Path=HistoricalData}"
                                 IsFilteringAllowed="False" ShowGroupPanel="False" CanUserSortColumns="False"
                              ClipboardPasteMode="OverwriteWithEmptyValues,Cells" SelectionUnit="FullRow" SelectionMode="Single" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Time}"
                                            DataFormatString="{} {0:dd, MMM, yyyy}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Rate}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</Window>

Code-Behind:
using System;
using System.Windows;
using System.Collections.ObjectModel;
 
namespace CutPaste
{
    public struct Data
    {
        public DateTime Time { get; set; }
        public double Rate { get; set; }
    }
    public partial class MainWindow : Window
    {
        public ObservableCollection<Data> HistoricalData { get; set; }
 
        public MainWindow()
        {
            HistoricalData = new ObservableCollection<Data>();
            for (int i = 0; i < 15; i++) {
                HistoricalData.Add(new Data() { Time = new DateTime(2013 + i, 1, 1), Rate = 100 * i });
            }
            InitializeComponent();
            DataContext = this;
        }
    }
}

Thanks again,
Louis
0
Maya
Telerik team
answered on 10 Oct 2013, 02:08 PM
Hi Louis,

Actually, that would be the expected behavior when you work with struct. Selection counts on hash code and Equals method to differentiate the items and when you paste one over the other, all its values are the same and they become equal. You will get the same behavior if you just edit the item so that two items have absolutely the same values.
You can test that behavior on DataGrid as well.   

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Louis
Top achievements
Rank 1
answered on 10 Oct 2013, 03:25 PM
I'm not sure I understand your explanation, as it doesn't seem to describe the behavior... Using the example I posted, if I paste a completely new row (no values matching) into an existing cell, I am then unable to paste anything (even another completely distinct row) anywhere below the original paste, as the location of the original paste remains selected (the orange selected color). I can select other rows in addition (they also become orange), but it will paste into the top-most selected row. Pasting distinct rows should not result in multiple rows with identical values as you describe, unless I am misunderstanding?

Edit: That also doesn't explain why pasting multiple rows into the bottom-most row doesn't append new rows.

Thanks,
Louis

0
Maya
Telerik team
answered on 15 Oct 2013, 03:40 PM
Hello Louis,

Actually, there will be a bunch of cases where RadGridView (and DataGrid as well) will not work as expected when items are of type struct since this is value type rather than reference. You can test for example editing an item with DataGrid - once you refresh the collection by sorting for instance, you will see that the item the modified value is reverted to its previous one. Furthermore, selection will not work correctly as well since it counts on hash code and Equals method. 
My recommendation would be to work with a reference type instead and, thus being able to benefit from all the features RadGridView provides. 

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Louis
Top achievements
Rank 1
Answers by
Vera
Telerik team
Louis
Top achievements
Rank 1
Maya
Telerik team
Share this question
or