Category / Section
How to copy DetailsViewDataGrid cell or row in WinForms DataGrid (SfDataGrid)?
1 min read
By default, you can copy a cells or rows in SfDataGrid based on the SelectionUnit. But in runtime you can change the SelectionUnit and copy both cells and rows in DetailsViewDataGrid by using context menu click events.
gridViewDefinition.DataGrid.RecordContextMenu = new ContextMenuStrip(); gridViewDefinition.DataGrid.RecordContextMenu.Items.Add("Copy Cell", null, OnCopyCellClicked); gridViewDefinition.DataGrid.RecordContextMenu.Items.Add("Copy Row", null, OnCopyRowClicked);private void OnCopyCellClicked(Object sender, EventArgs e) { var rowindex= this.sfDataGrid1.SelectedDetailsViewGrid.CurrentCell.RowIndex; var column = this.sfDataGrid1.SelectedDetailsViewGrid.CurrentCell.ColumnIndex; gridViewDefinition.DataGrid.SelectionUnit = Syncfusion.WinForms.DataGrid.Enums.SelectionUnit.Cell; sfDataGrid1.SelectedDetailsViewGrid.MoveToCurrentCell(new Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex(rowindex, column)); sfDataGrid1.SelectedDetailsViewGrid.ClipboardController.Copy(); } private void OnCopyRowClicked(Object sender, EventArgs e) { var rowindex = this.sfDataGrid1.SelectedDetailsViewGrid.CurrentCell.RowIndex; var column = this.sfDataGrid1.SelectedDetailsViewGrid.CurrentCell.ColumnIndex; gridViewDefinition.DataGrid.SelectionUnit = Syncfusion.WinForms.DataGrid.Enums.SelectionUnit.Row; sfDataGrid1.SelectedDetailsViewGrid.MoveToCurrentCell(new Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex(rowindex, column)); sfDataGrid1.SelectedDetailsViewGrid.ClipboardController.Copy(); }