My development environment: Microsoft Visual Studio. NET 2005
This program is the Windows Forms application
Create a new Windows Forms Application project, open Form1, place a DataGridView control and button on the form, add two columns to the columns of DataGridView, and name Stuname ( "Name" is not available here because it conflicts with the name of the control) and age. The following figure:
The overall code is as follows:
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Text;
Using System.Windows.Forms;
Namespace Wind
{
public partial class Form1:form
{
int c = 0;
Public Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
DataGridViewRow dr = new DataGridViewRow ();
Dr. Createcells (DGV);
Dr. Cells[0]. Value = "H1";
Dr. CELLS[1]. Value = (++c);
DGV. Rows.insert (0, Dr); The inserted data appears as the first line
DGV. Rows.Add (DR); The inserted data is displayed as the last line
}
}
}
Run by F5 to see the results of the run. The following are the results of the operation as the first row was inserted: