How to copy flexgrid rows

Posted by: soraroid on 27 February 2025, 9:54 pm EST

    • Post Options:
    • Link

    Posted 27 February 2025, 9:54 pm EST

    Hello.

    I have a few questions.

    1. When a button is pressed, I want to copy the data the data of the currently focused flexgrid row (startediting mode) to the data of the row above that row and keep the cursor in its current state. ( copy row : Copy the upper line to the lower line)

      ex) If you press the button when the current focus is in startediting mode in grid.cells[3,2], I want to copy the entire data from Grid.rows[2] to Grid.rows[3] and keep the focus intact.

    2. I don’t want to use the … function in the flexgrid header. I would like to know how to remove that feature.

  • Posted 28 February 2025, 5:43 am EST

    Hi,

    To copy the selected Cells/Row Data, you may call the Copy() method from FlexGrid instance.

    public void CopyGridData(){
            grid.Copy(); //grid is FlexGrid instance
        }

    To disable the three dots from the column headers, we need to set the ColumnOptionsMenuVisibility to GridColumnOptionsMenuVisibility.Collapsed.

    <FlexGrid @ref="grid" ItemsSource="Maps" AutoGenerateColumns="false" ColumnOptionsMenuVisibility="GridColumnOptionsMenuVisibility.Collapsed">
    </FlexGrid>

    Hope it helps!

    Regards,

    Manish Gupta

  • Posted 3 March 2025, 8:46 pm EST

    Thank you.

    However the first problem has not yet been solved.

    The method you mentioned copies the contents of the selected cell/row,

    and what I want to do is to copy and insert the contents of a specific location into the selected cell/row.

    (Cells/rows containing content to copy are not selected)

    Please provide example source.

  • Posted 4 March 2025, 7:51 am EST

    Hi,

    Apologies, but I couldn’t fully understand your requirement. Could you please clarify it with an example? Specifically, what exact actions do you need?

    It would be helpful if you could share a screenshot showing the initial state of the grid (grid cells) along with the expected outcome. This will allow us to better understand your requirement and provide an appropriate solution.

    Regards,

    Ankit

  • Posted 6 March 2025, 2:17 am EST - Updated 6 March 2025, 2:22 am EST

    When the cursor is blinking in cell[1,2], press the red button.

    (ref. ‘Before.png’)

    Then, I want the entire row[0] to be copied to row[1] and the text in cell[1,2] to be in a block state.

    (ref. ‘After.png’)

    Please include example source.

  • 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

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels