Crash when copying cell value to row
I have an sfDataGrid bound to an underlying observable collection of objects. If a user selects a cell, copies the value, then selects the row and hits <ctrl-v> to paste I get a crash. This is using version 24.2.9.
Here's my xaml:-
<Window x:Class="testgridcopy.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:testgridcopy"
xmlns:sf="http://schemas.syncfusion.com/wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<sf:SfDataGrid ItemsSource="{Binding TestObjects}"
AutoGenerateColumns="True" AutoGenerateColumnsMode="SmartReset"
AllowResizingColumns="True" ColumnSizer="Auto"
ShowRowHeader="True" SelectionMode="Multiple"
AllowEditing="True" EditTrigger="OnTap"
AllowDeleting="True" SelectionUnit="Row"
Grid.Row="0" Margin="2,2,2,2"
CurrentCellActivated="OnCurrentCellActivated"
GridCopyOption="None">
<sf:SfDataGrid.Columns>
<sf:GridTemplateColumn sf:FocusManagerHelper.WantsKeyInput="True">
<sf:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="x"
sf:FocusManagerHelper.FocusedElement="True"
sf:VisualContainer.WantsMouseInput="True"
ClickMode="Press"
Click="DeleteTestObject_Click"
Width="Auto"
ToolTip="Delete Test Object"
Tag="{Binding}" />
</DataTemplate>
</sf:GridTemplateColumn.CellTemplate>
</sf:GridTemplateColumn>
</sf:SfDataGrid.Columns>
</sf:SfDataGrid>
<Button Click="AddTestObject_Click" Grid.Row="1" HorizontalAlignment="Left" Width="100" Margin="2">Add</Button>
</Grid>
</Window>
And my Code Behind:-
using Syncfusion.UI.Xaml.Grid;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace testgridcopy
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ViewModel mViewModel;
public MainWindow()
{
InitializeComponent();
mViewModel = new ViewModel();
DataContext = mViewModel;
}
private void OnCurrentCellActivated(object sender, CurrentCellActivatedEventArgs e)
{
var datagrid = sender as SfDataGrid;
if (datagrid != null)
{
if (datagrid.SelectionController != null)
{
if (datagrid.SelectionController.CurrentCellManager != null)
{
if (datagrid.SelectionController.CurrentCellManager.CurrentCell != null)
{
//Here call the BeginEdit method to enter the edit mode in SfDataGrid
if (!datagrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing)
datagrid.SelectionController.CurrentCellManager.BeginEdit();
}
}
}
}
}
private void AddTestObject_Click(object sender, RoutedEventArgs e)
{
mViewModel.TestObjects.Add(new TestObject());
}
private void DeleteTestObject_Click(object sender, EventArgs e)
{
mViewModel.TestObjects.Remove((sender as Button).Tag as TestObject);
}
}
public class ViewModel
{
public ViewModel()
{ TestObjects = new ObservableCollection<TestObject>(); }
public ObservableCollection<TestObject> TestObjects { get; set; }
}
public class TestObject
{
public string Property1 { get; set; }
public string Property2 { get; set; }
public string Property3 { get; set; }
}
}
To replicate, follow these exact steps:-
- Click add to add a new row
- Click in the Property1 cell
- Type a value, e.g. "Hello"
- Select the value and press <ctrl-c> to put it on the clipboard
- Click the row header to select the entire row
- Press <ctrl-v> to paste the clipboard content
Thank you for your cooperation
Manikanda Akash M
Attachment: SfDataGrid_Demo4_8_172232a.zip
That worked perfectly. Thank you for such a prompt response.
Hi Declan Hillier,
You're welcome. Please get back to us if you need any further assistance, we will be happy to help you.
Regards,
Manikanda Akash M
- 3 Replies
- 2 Participants
- Marked answer
-
DH Declan Hillier
- Aug 12, 2024 01:20 PM UTC
- Aug 15, 2024 03:38 AM UTC