private void InitializeGrid(int rows, int columns) { try { dataGridView1.ColumnCount = columns; dataGridView1.ColumnHeadersVisible = true; DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle(); columnHeaderStyle.BackColor = Color.Beige; columnHeaderStyle.Font = new Font("Times new roman", 12, FontStyle.Bold); dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderStyle; for (int i = 0; i < columns; i++) { dataGridView1.Columns[i].Name = LetterNumberConverter.NumberToLetter(i); } dataGridView1.RowCount = rows; dataGridView1.RowHeadersVisible = true; DataGridViewCellStyle rowHeaderStyle = new DataGridViewCellStyle(); rowHeaderStyle.BackColor = Color.Beige; rowHeaderStyle.Font = new Font("Times new roman", 12, FontStyle.Bold); dataGridView1.ColumnHeadersDefaultCellStyle = rowHeaderStyle; for (int i = 0; i < rows; i++) { dataGridView1.Rows[i].HeaderCell.Value = (i).ToString(); } for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { DataCell cell = new DataCell(); cell.name_set(dataGridView1.Columns[j].Name + dataGridView1.Rows[i].HeaderCell.Value); cell.column = j; cell.row = i; Data.DataAdd(cell); } } Data.columns = columns; Data.rows = rows; } catch (Exception) { } }
public int AddColumn(int _c, DataGridView dgv) { _c++; DataGridViewColumn column = (DataGridViewColumn)dgv.Columns[0].Clone(); column.HeaderCell.Value = LetterNumberConverter.NumberToLetter(_c - 1); dgv.Columns.Add(column); for (int i = 0; i < dataGridView1.RowCount; i++) { DataCell cell = new DataCell(); cell.name_set(dataGridView1.Columns[_c - 1].Name + dataGridView1.Rows[i].HeaderCell.Value); cell.column = _c - 1; cell.row = i; Data.DataAdd(cell); } Data.columns++; return(0); }
public int AddRow(int _c, DataGridView dgv) { _c++; DataGridViewRow row = (DataGridViewRow)dgv.Rows[0].Clone(); row.HeaderCell.Value = (_c - 1).ToString(); dgv.Rows.Add(row); for (int i = 0; i < dataGridView1.ColumnCount; i++) { DataCell cell = new DataCell(); cell.name_set(dataGridView1.Columns[i].Name + dataGridView1.Rows[_c - 1].HeaderCell.Value); cell.column = i; cell.row = _c - 1; Data.DataAdd(cell); } Data.rows++; return(0); }