private void updateCols() { m_dataGridView.Columns[0].Visible = false; var tblInfo = new ParagraphsTblInfo(); int i = 1; for (; i < m_dataGridView.ColumnCount; i++) { //show hide columns if (tblInfo.m_cols[i].m_visible == false) { m_dataGridView.Columns[i].Visible = false; continue; } m_dataGridView.Columns[i].HeaderText = tblInfo.m_cols[i].m_alias; #if header_blue //header color blue m_dataGridView.Columns[i].HeaderCell.Style.BackColor = Color.Blue; m_dataGridView.Columns[i].HeaderCell.Style.ForeColor = Color.White; m_dataGridView.Columns[i].Width = 50; #endif } m_dataGridView.Columns[i - 2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; m_dataGridView.Columns[i - 2].FillWeight = 1; m_dataGridView.Columns[i - 2].MinimumWidth = 100; }
public EditPanel(bool showCmb = false) { TableLayoutPanel tlp = new TableLayoutPanel { Dock = DockStyle.Fill, CellBorderStyle = TableLayoutPanelCellBorderStyle.None }; m_tlp = tlp; tlp.RowStyles.Add(new RowStyle() { SizeType = SizeType.Absolute, Height = 35 }); tlp.RowStyles.Add(new RowStyle() { SizeType = SizeType.Percent, Height = 100 }); tlp.RowStyles.Add(new RowStyle() { SizeType = SizeType.Absolute, Height = 35 }); //row1 var titleLbl = new Label { Text = "Title", AutoSize = true, Margin = new Padding(0, 5, 0, 0), Visible = false }; m_titleLbl = titleLbl; var titleCmb = new ComboBox(); titleCmb.Visible = false; m_titlesCmb = titleCmb; var spn = new FlowLayoutPanel { AutoSize = true, Anchor = AnchorStyles.Right, FlowDirection = FlowDirection.LeftToRight }; var closeBtn = new Button() { Text = "close", AutoSize = true, }; m_closeBtn = closeBtn; closeBtn.Click += CloseBtn_Click; spn.Controls.AddRange(new Control[] { m_titleLbl, m_titlesCmb, closeBtn }); //show cmb if (showCmb) { spn.Anchor = AnchorStyles.Left; m_titlesCmb.Visible = true; m_titleLbl.Visible = true; m_closeBtn.Visible = false; } tlp.Controls.Add(spn, 0, 0); var dgv = new DataGridView { Dock = DockStyle.Fill }; tlp.Controls.Add(dgv, 0, 1); var saveBtn = new Button { AutoSize = true, Text = "submit", }; saveBtn.Click += SaveBtn_Click; var cancelBtn = new Button { AutoSize = true, Text = "reload" }; cancelBtn.Click += CancelBtn_Click; var spn2 = new FlowLayoutPanel { AutoSize = true, FlowDirection = FlowDirection.LeftToRight, Anchor = AnchorStyles.Right }; spn2.Controls.AddRange(new Control[] { saveBtn, cancelBtn }); tlp.Controls.Add(spn2, 0, 2); //data m_dataTable = new DataTable(); m_dataTable.TableNewRow += M_dataTable_TableNewRow; m_bindingSource = new BindingSource(); m_bindingSource.DataSource = m_dataTable; dgv.DataSource = m_bindingSource; m_dataGridView = dgv; dgv.AutoGenerateColumns = false; dgv.DataError += DataGridView1_DataError; dgv.CellParsing += OnCellParsing; dgv.CellFormatting += Dgv_CellFormatting; dgv.RowsAdded += Dgv_RowsAdded; m_tblInfo = new ParagraphsTblInfo(); crtColumns(); }