一、鼠標左鍵取得選中的行this
DataGridViewSelectedRowCollection rows = this.dataGridView1.SelectedRows;orm
二、遍歷選中的行io
foreach (DataGridViewRow dr in rows)
{
strPersonCode = dr.Cells["colPersonCode"].Value.ToString();
strCardNo = dr.Cells["colCardNo"].Value.ToString();
strNewTime = dr.Cells["colNewTime"].Value.ToString();
}object
三、給DataGridView第一列繪製行號foreach
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 - 2,
e.RowBounds.Height);遍歷
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
dataGridView1.RowHeadersDefaultCellStyle.Font,
rectangle,
dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}im
四、清空DataGridView全部行co
this.dataGridView.Rows.Clear();data