Paste issues with GridView

6 posts, 0 answers
  1. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 04 Oct 2013 Link to this post

    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
  2. Vera
    Admin
    Vera avatar
    263 posts

    Posted 09 Oct 2013 Link to this post

    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 >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 09 Oct 2013 Link to this post

    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
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 10 Oct 2013 Link to this post

    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 >>
  6. Louis
    Louis avatar
    83 posts
    Member since:
    Aug 2013

    Posted 10 Oct 2013 Link to this post

    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

  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 15 Oct 2013 Link to this post

    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 >>
Back to Top
UI for WPF is Visual Studio 2017 Ready