public SummaryControlContainer(DataGridViewSummary dgv) { if (dgv == null) { throw new Exception("DataGridView is null!"); } this.dgv = dgv; sumBoxHash = new Hashtable(); sumRowHeaderLabel = new Label(); this.dgv.CreateSummary += new EventHandler(dgv_CreateSummary); this.dgv.RowsAdded += new DataGridViewRowsAddedEventHandler(dgv_RowsAdded); this.dgv.RowsRemoved += new DataGridViewRowsRemovedEventHandler(dgv_RowsRemoved); this.dgv.CellValueChanged += new DataGridViewCellEventHandler(dgv_CellValueChanged); this.dgv.Scroll += new ScrollEventHandler(dgv_Scroll); this.dgv.ColumnWidthChanged += new DataGridViewColumnEventHandler(dgv_ColumnWidthChanged); this.dgv.RowHeadersWidthChanged += new EventHandler(dgv_RowHeadersWidthChanged); this.VisibleChanged += new EventHandler(SummaryControlContainer_VisibleChanged); this.dgv.ColumnAdded += new DataGridViewColumnEventHandler(dgv_ColumnAdded); this.dgv.ColumnRemoved += new DataGridViewColumnEventHandler(dgv_ColumnRemoved); this.dgv.ColumnStateChanged += new DataGridViewColumnStateChangedEventHandler(dgv_ColumnStateChanged); this.dgv.ColumnDisplayIndexChanged += new DataGridViewColumnEventHandler(dgv_ColumnDisplayIndexChanged); }
//新增行号实现功能 private void SetHeaderValue(DataGridViewSummary dgv) { int rowHeaderNum = 1; if (dgv != null && dgv.ShowRowNumber) { foreach (DataGridViewRow r in dgv.Rows) { //设置HeaderCell的值 //r.HeaderCell.Value = "第" + rowHeaderNum.ToString() + "行"; r.HeaderCell.Value = rowHeaderNum.ToString(); r.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; //r.HeaderCell.OwningColumn //每十行变成红色的 //if (rowHeaderNum % 10 == 0) // r.DefaultCellStyle.BackColor = Color.Red; //每十行变成红色的 rowHeaderNum++; } } }