DataGridView控件显示行号

private void dgvKBRollUp_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            if (dgvKBRollUp.Rows.Count != 0)
            {
                for (int i = 0; i < e.RowCount; i++)
                {
                    this.dgvKBRollUp.Rows[e.RowIndex + i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                    this.dgvKBRollUp.Rows[e.RowIndex + i].HeaderCell.Value = (e.RowIndex + i + 1).ToString();
                }

                for (int i = e.RowIndex + e.RowCount; i < this.dgvKBRollUp.Rows.Count; i++)
                {
                    this.dgvKBRollUp.Rows[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                    this.dgvKBRollUp.Rows[i].HeaderCell.Value = (i + 1).ToString();
                }
 
            }

你可能感兴趣的:(datagridview)