Home Forums WinForms controls Xceed Grid for WinForms Select all grid rows and copy

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16659 |

    Hey Guys,

    Am I dreaming or is it really true that the .Net DataGrid does not allow select and copy of all rows from the grid out of the box?

    Thanks,

    DeeKay

    Imported from legacy forums. Posted by DeeKay (had 946 views)

    User (Old forums)
    Member
    Post count: 23064

    There is in fact no such “out-of-the-box” feature.  However, it depends what you want to do.  If you simply want to copy values to the clipboard, you can do something like the following :

    private void CopyToClipboard()

    {

        // Create the DataObject that will be used during the copy/paste
        // operations.
        //
        // We will only add the plain text DataFormat.
        // The cell values are separated by a TAB and the rows
        // are separated by a carriage return.
        //
        // If you want to add other DataFormats (such as HTML),
        // you will need to create it and add it to the DataObject using
        // the SetData method with the appropriate DataFormat.

        DataObject data = new DataObject();

        string text = string.Empty;

        // We will only copy the row(s)/cell(s) values of the selected rows
        // which contain cells. Any other rows will be ignored.

        foreach( Row row in gridControl1.SelectedRows )

        {

            if( row is CellRow )

            {

                foreach( Cell cell in ( ( CellRow )row ).Cells )

                {

                    text += cell.Value.ToString() +

    “\t”;

                }

                text +=

    Environment.NewLine;

            }

        }

        // Set our plain text DataFormat.

        data.SetData(

    DataFormats.Text, text );

        // Copy the row(s)/cell(s) values of the selected rows to the clipboard.

        Clipboard.SetDataObject( data );

    }

    If you want drag and drop functionalities, we have a few samples you can look at which show how to do this.

    http://www.xceedsoft.com/cs/download/XceedGrid/CSharp/Drag and drop samples.zip

     

    Imported from legacy forums. Posted by André (had 1454 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.