Welcome to the Xceed Community | Help
Community Search  

Select all grid rows and copy

Sort Posts: Previous Next
  •  11-21-2008, 2:28 PM Post no. 17095

    Select all grid rows and copy

    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

    Filed under:
  •  11-24-2008, 12:03 PM Post no. 17117 in reply to 17095

    Re: Select all grid rows and copy

    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

     


    André
    Software Developer and Tech Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.