private void SetDataGridViewStyle(DataGridView dv) { dv.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dv.MultiSelect = false; dv.ReadOnly = true; dv.AllowUserToAddRows = false; dv.DefaultCellStyle.BackColor = this.BackColor;// System.Drawing.Color.FromArgb(230, 230, 230); dv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill ; dv.BackgroundColor = Color.White; dv.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dataGridView_RowPostPaint); } /// <summary> /// 使datagridview的行标显示行号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor)) { e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentCulture), dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4); } }