2X faster development
The ultimate WPF UI toolkit to boost your development speed.
You can paste the copied row in AddNewRow by overriding the PasteTextToRow method in GridCutCopyPaste class in WPF DataGrid (SfDataGrid). XAML <syncfusion:SfDataGrid x:Name="sfdatagrid" AddNewRowPosition="Top" AllowEditing="True" AutoGenerateColumns="True" GridCopyOption="CopyData" ItemsSource="{Binding EmployeeDetails}" SelectionMode="Extended" SelectionUnit="Row" /> C# this.sfdatagrid.GridCopyPaste = new CustomPaste(sfdatagrid); … public class CustomPaste : GridCutCopyPaste { public CustomPaste(SfDataGrid sfgrid) : base(sfgrid) { } protected override void PasteTextToRow() { IDataObject dataObject = null; dataObject = Clipboard.GetDataObject(); var clipBoardContent = dataObject.GetData(DataFormats.UnicodeText) as string; string[] records = Regex.Split(clipBoardContent.ToString(), @"\r\n"); if (dataGrid.SelectionUnit == GridSelectionUnit.Row) { dataGrid.Focus(); bool isAddNewRow= this.dataGrid.IsAddNewIndex(this.dataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex); //Checking for row is AddNewRow. if (isAddNewRow) { if (!this.dataGrid.View.IsAddingNew) return; string[] record = Regex.Split(records[0], @"\t"); var provider = this.dataGrid.View.GetPropertyAccessProvider(); var rowData = (this.dataGrid.View as CollectionViewAdv).CurrentAddItem; //Paste the copied row in each cell. foreach (var column in this.dataGrid.Columns) { var cellText = provider.GetValue(rowData, column.MappingName); if (cellText == null) { PropertyDescriptorCollection typeInfos = this.dataGrid.View.GetItemProperties(); var typeInfo = typeInfos.GetPropertyDescriptor(column.MappingName); } CommitValue(rowData, column, provider, record[this.dataGrid.Columns.IndexOf(column)]); } } } else base.PasteTextToRow(); } }
Note:
You can only paste the copied row after initiating the AddNewRow by editing. |
2X faster development
The ultimate WPF UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.