new public void initDataGridViewColumn(DataGridView dataGridView) { m_dataGridView = dataGridView; dataGridView.ColumnCount = m_columnsInfo.Count; setDataGridViewStyle(); for (int i = 0; i < m_columnsInfo.Count; i++) { DataGridViewColumnInfoStruct column = new DataGridViewColumnInfoStruct(); column = (DataGridViewColumnInfoStruct)m_columnsInfo[i]; dataGridView.Columns[i].Width = column.Width; dataGridView.Columns[i].HeaderText = column.headerText; dataGridView.Columns[i].Visible = column.isVisiable; dataGridView.Columns[i].ReadOnly = column.isReadOnly; // 禁止点击列头自动排序功能 dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; if (column.isReadOnly) { dataGridView.Columns[i].DefaultCellStyle.BackColor = System.Drawing.Color.AliceBlue; } } dataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.LightSkyBlue; }
public void addDataGridViewColumn(string headerText, int Width, bool isVisiable = true) { DataGridViewColumnInfoStruct column = new DataGridViewColumnInfoStruct(); column.headerText = headerText; column.Width = Width; column.isVisiable = isVisiable; m_columnsInfo.Add(m_columnsInfo.Count, column); }
public void initDataGridViewColumn(DataGridView dataGridView) { m_dataGridView = dataGridView; dataGridView.ColumnCount = m_columnsInfo.Count; setDataGridViewStyle(); for (int i = 0; i < m_columnsInfo.Count; i++) { DataGridViewColumnInfoStruct column = new DataGridViewColumnInfoStruct(); column = (DataGridViewColumnInfoStruct)m_columnsInfo[i]; dataGridView.Columns[i].Width = column.Width; dataGridView.Columns[i].HeaderText = column.headerText; dataGridView.Columns[i].Visible = column.isVisiable; } }