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

total gridview in clipboard

2 Answers 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kristof
Top achievements
Rank 1
Kristof asked on 23 Mar 2010, 10:03 AM

Hello

Is there a possibility to get the data (all records) in a gridview to the clipboard?
Because I have seen that just the selected row will be copied to the clipboard.
Is there a select all or something...

Or is the only solution to export the data in a file.
Is there an other solution?

This is the data from the clipboard after select a row:
TR20100302_00004 CDGGT8 BCNGT1  02/03/2010  00:00  02/03/2010  15:30    
You can find a screenshot of my gridview in attach.

Thanks and regards,
Kristof

2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 23 Mar 2010, 12:15 PM
Hi Kristof,

You can disable the grid default copy to clipboard operation and perform your own:

XAML
<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
    xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"
    xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <telerikGrid:RadGridView ItemsSource="{Binding Data}" telerik:Clipboard.IsEnabled="False" KeyDown="RadGridView_KeyDown" />
    </Grid>
</UserControl>


C#
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using System.Windows.Input;
using Telerik.Windows.Controls;
 
namespace SilverlightApplication1
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
            DataContext = new MyDataContext();
        }
 
        private void RadGridView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
            {
                var data = ((RadGridView)sender).ToText(true, true);
                Clipboard.SetData(e, data);
            }
        }
    }
 
    public class MyDataContext
    {
        ObservableCollection<MyObject> _Data;
        public IEnumerable<MyObject> Data
        {
            get
            {
                if (_Data == null)
                {
                    _Data = new ObservableCollection<MyObject>();
 
                    (from i in Enumerable.Range(0, 10)
                     select new MyObject() { ID = i, Name = String.Format("Name{0}", i) }).ToList().ForEach(_Data.Add);
                }
 
                return _Data;
            }
        }
    }
 
    public class MyObject
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}



Regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kristof
Top achievements
Rank 1
answered on 23 Mar 2010, 04:52 PM
Hi Vlad,

That works perfect! ;-)

Thanks,
Kristof
Tags
GridView
Asked by
Kristof
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Kristof
Top achievements
Rank 1
Share this question
or