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

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)