FlexGrid: Automatically Copy and Paste Selected Rows

Posted by: arockwel on 26 March 2018, 2:17 pm EST

    • Post Options:
    • Link

    Posted 26 March 2018, 2:17 pm EST

    I have a FlexGrid where I would like to select a certain number of rows, for example 6 rows out of 20 that are in the grid. Then I would like to click a button which copies the contents of each column in those 6 rows; inserts the same number of rows originally selected (6) to the bottom of the grid; and then pastes that copied data into the newly added rows. This would end up having 26 rows in the grid. Is there a preferred way to do this using C# code?

  • Posted 27 March 2018, 2:29 am EST

    Hi Aaron!

    You can take advantage of AutoClipboard property, Copy and Paste methods of the grid for this.

    private void _btnCopyPasteRows_Click(object sender, EventArgs e)
    {
            bool cb = c1FlexGrid1.AutoClipboard;
            c1FlexGrid1.AutoClipboard = true;
    
            c1FlexGrid1.Select(c1FlexGrid1.Selection.r1, 1, c1FlexGrid1.Selection.r2, c1FlexGrid1.Cols.Count - 1);
            c1FlexGrid1.Copy();
    
            int selectedRowsCount = c1FlexGrid1.Selection.r2 - c1FlexGrid1.Selection.r1 + 1;
            int currentTotalRows = c1FlexGrid1.Rows.Count;
            c1FlexGrid1.Rows.Count += selectedRowsCount;
    
            c1FlexGrid1.Select(currentTotalRows, 1, c1FlexGrid1.Rows.Count - 1, c1FlexGrid1.Cols.Count - 1);
            c1FlexGrid1.Paste();
    
            c1FlexGrid1.AutoClipboard = cb;
    }
    

    Best regards,

    Meenakshi

  • Posted 27 March 2018, 4:16 pm EST

    Meenakshi,

    Thank you! I will give that a try, but it looks like it should work.

    Aaron

Need extra support?

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

Learn More

Forum Channels