Asp.net datagri Copy to clipboard method

Source: Internet
Author: User

Asp tutorial. net datagridview Copy to clipboard method

Copy mode settings

 

Maid copymode = maid copymode. enablewithoutheadertext // sets the replicable mode

 

The datagridview. clipboardcopymode attribute gets or sets a value, which indicates whether the user can copy the text value of the cell to the clipboard, and whether the row title and column title text are included.

 

Namespace: system. windows. forms

Assembly: system. windows. forms (in system. windows. forms. dll)

 

Selected copy

 

Clipboard. setdataobject (datagridview1.getclipboardcontent () // place the data selected by the control to the system clipboard.

 

Datagridview paste

 

Code

If (MAID. value = null)

{

Return;

}

Int insertrowindex = maid. rowindex;

String pastetext = clipboard. gettext (); // obtain data from the system clipboard

If (string. isnullorempty (pastetext ))

{

Return;

}

String [] lines = pastetext. split ('r'); // group by row

Bool isheader = true;

Foreach (string line in lines)

{   

If (isheader)

    {

Isheader = false; // filter operations when the title is included in the replicable mode

    }

Else

    {

String [] vals = line. split ('t'); // grouping by tab space

If (vals. length-1! = Maid)

        {

Throw new applicationexception ("column number error ");

        }

Maid row = maid [insertrowindex];

Row. headercell. value = vals [0];

For (int I = 0; I <row. cells. count-1; I ++)

        {

Row. cells [I]. value = vals [(I + 1)];

        }

Insertrowindex + = 1;

    }

}

 

 

IX. Automatic ID of the datagridview

 

Code

 

Private void maid (object sender, maid e)

        {

// The automatic number is irrelevant to the database tutorial.

Rectangle = new rectangle (e. rowbounds. location. x, e. rowbounds. location. y

, Maid-4, e. rowbounds. height );

 

Textrenderer. drawtext (e. graphics, (e. rowindex + 1). tostring (), datagridview1.

Rowheadersdefaultcellstyle. font, rectangle,

Datagridview1.rowheadersdefaultcellstyle. forecolor, textformatflags. verticalcenter | textformatflags. right );

        }

 

Show row number

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.