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