/// <summary> /// 表格刷新,设置完表格后一定要进行刷新 /// </summary> public void RefreshGrid() { int InsertRow = 0; if (this.m_MeterNum % this.m_RowMeterNum != 0) { InsertRow = (int)this.m_MeterNum / this.m_RowMeterNum + 1; } else { InsertRow = (int)this.m_MeterNum / this.m_RowMeterNum; } int _Rows = (InsertRow) * 2; int _Cols = m_RowMeterNum * 4; //一个表位有3列一列列距离,多选框,表位号,文本框,最后一列不需要列距所以 Dgw.Rows.Clear(); Dgw.Columns.Clear(); #region -------------------------------创建列--------------------------------------------------- for (int i = 0; i < _Cols; i++) { int _ColIndex; if (i % 4 != 0) { continue; } _ColIndex = Dgw.Columns.Add("Col" + i.ToString(), ""); this.SetColumnStyleWithColSpace(Dgw.Columns[_ColIndex]); //列距离 CreateColumnStyleWithCheckBox(_ColIndex + 1); _ColIndex = Dgw.Columns.Add("Col" + (i + 1).ToString(), ""); this.SetColumnStyleWithBwh(Dgw.Columns[_ColIndex]); //表位号 _ColIndex = Dgw.Columns.Add("Col" + (i + 3).ToString(), ""); this.SetColumnStyleWithText(Dgw.Columns[_ColIndex]); //文本 if (_ColIndex == _Cols - 1) //多加一列作为列间距 { _ColIndex = Dgw.Columns.Add("Col" + i.ToString(), ""); this.SetColumnStyleWithColSpace(Dgw.Columns[_ColIndex]); //列距离 } } #endregion int _Bwh = 0; Meter = new Dictionary <int, CellRowCol>(); for (int i = 0; i < _Rows; i++) { int _RowIndex = Dgw.Rows.Add(); if (i % 2 == 0) //插入行距行 { Dgw.Rows[_RowIndex].Height = this.m_RowSpace; continue; } Dgw.Rows[_RowIndex].Height = this.m_RowHeight; //插入数据行 for (int j = 0; j < _Cols; j++) { if (j % 4 != 0) { continue; } _Bwh++; if (_Bwh > this.m_MeterNum) //如果超过表位数则不显示任何数据 { Dgw.Rows[_RowIndex].Cells[j + 1].Tag = 0; Dgw.Rows[_RowIndex].Cells[j + 2].Value = ""; //插入表位号 Dgw.Rows[_RowIndex].Cells[j + 3].Tag = 0; } else { Dgw.Rows[_RowIndex].Cells[j + 1].Tag = _Bwh; Dgw.Rows[_RowIndex].Cells[j + 1].ReadOnly = true; Dgw.Rows[_RowIndex].Cells[j + 2].Value = _Bwh.ToString("D2"); //插入表位号 Dgw.Rows[_RowIndex].Cells[j + 3].Tag = _Bwh; Dgw.Rows[_RowIndex].Cells[j + 3].ReadOnly = true; CellRowCol _Item = new CellRowCol(); _Item.Row = _RowIndex; _Item.Col = j + 3; Meter.Add(_Bwh, _Item); } } } }