1。向DataGridView中插入数据
m_index = this.dataGridView1.Rows.Add();
m_currentTime = DateTime.Now.ToLocalTime().ToString();
this.dataGridView1.Rows[m_index].Cells[0].Value = m_currentTime;
this.dataGridView1.Rows[m_index].Cells[1].Value = m_aName;
this.dataGridView1.Rows[m_index].Cells[2].Value = m_aScore;
this.dataGridView1.Rows[m_index].Cells[3].Value = m_aK;
2。将DataGridView表格自动编号
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) {
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dataGridView1.RowHeadersWidth – 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics,
(e.RowIndex + 1).ToString(),
dataGridView1.RowHeadersDefaultCellStyle.Font,
rectangle,