- // 应该设置下面属性,防止行号被掩盖
- // dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
- void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
- {
- RefreshDataGridViewLineNumber(e.RowIndex);
- }
- void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
- {
- RefreshDataGridViewLineNumber(e.RowIndex);
- }
- private void RefreshDataGridViewLineNumber(int index)
- {
- for (int i = index; i < dataGridView1.Rows.Count; i++)
- {
- this.dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
- }
- }
本文转自 h2appy 51CTO博客,原文链接:http://blog.51cto.com/h2appy/827738,如需转载请自行联系原作者