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,
爱站程序员基地
![(原创)[C#] 一步一步自定义拖拽(Drag&Drop)时的鼠标效果:(一)基本原理及基本实现-爱站程序员基地](https://aiznh.com/wp-content/uploads/2022/07/20220721231016-62d9dcd85c40b-220x150.gif)

