Posted 6 March 2025, 5:48 am EST
- Updated 6 March 2025, 5:53 am EST
Hi,
Thank you for sharing your use case with us. Based on your use case, you could use the following code to meet your requirement. Execute the following code on button press:
async Task OnCopyBtnClick()
{
bool isEditing = grid.ActiveEditor != null;
if (isEditing) await grid.FinishRowEditing();
GridCellRange currRange = grid.CursorRange;
if (currRange.Row == 0) return;
for (int i = 0; i < grid.Columns.Count; i++)
{
grid.SetCellValue(GridCellType.Cell, currRange.Row, i,
grid.GetCellValue(GridCellType.Cell, new GridCellRange(currRange.Row - 1, i)));
}
if (isEditing)
{
await grid.FocusAsync();
await grid.StartEditingAsync(currRange.Row, currRange.Column, false);
}
}
It will copy the content from the upper row, and also it maintains the editing state, i.e, if the grid is in edit mode, before, pressing the button, it will remain in the edit mode.
You could refer to the attached sample that demonstrates the same. Let us know if you face any issues.
References:
GetCellValue method: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.FlexGrid~GetCellValue(GridCellType,GridRow,GridColumn).html
SetCellValue method: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.FlexGrid~SetCellValue(GridCellType,Int32,Int32,Object).html
StartEditingAsync method: https://developer.mescius.com/componentone/docs/blazor/online-blazor/C1.Blazor.Grid~C1.Blazor.Grid.FlexGrid~StartEditingAsync(Int32,Int32,Boolean,Boolean,Boolean).html
Regards,
Ankit
Copy_Rows.zip
