C # dynamically adds rows, deletes rows

Source: Internet
Author: User

There is a line:

Click Add, adding the same line below

The newly added row has a column delete button, and when you click the Delete button of a row, delete the forward

Method:

Haha, I'm so smart.

1, text box, text box, add button 2, a DataGridView (put in a panel), three columns are text box, text box, button column DataGridView: Hide title bar: Datagridview1.columnheadersvisible = false; Hide first column: Rowheadersvisible=false; Do not automatically add new lines: Allowusertoaddrows=false; hide border: borderstyle=none; set a column for the button: Columntype:datagridviewbuttoncolumn displays the text on the button column : Set the Button Column property: Usecolumntextforbuttonvalue = true; Click on the ' Add ' button, in the button event, DataGridView add a column
this. DATAGRIDVIEW1.ROWS.ADD ();

When you click the Delete button for a row, delete the forward

Private voidDatagridview1_cellcontentclick (Objectsender, DataGridViewCellEventArgs e) {        if(E.rowindex >=0) {datagridviewcolumn column=Datagridview1.columns[e.columnindex]; if(column isdatagridviewbuttoncolumn) {                //Here you can write any action you need about the button event ~//MessageBox.Show ("button is clicked"); //This.datagridview1.currentrow.visible=false;//Hide Current Line                 This. dataGridView1.Rows.RemoveAt (E.rowindex);//Delete current row            }        }    }

The little reptile crawls my webpage ...

C # dynamically adds rows, deletes rows

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.