private void frmInstruments_Load(object sender, EventArgs e) { cboSortSearch.Items.Add(new ComboBoxItem { Text = "Instrument ID", Value = "InstrumentID" }); cboSortSearch.Items.Add(new ComboBoxItem { Text = "Instrument Description", Value = "Description" }); cboSortSearch.Items.Add(new ComboBoxItem { Text = "Serial Number", Value = "SerialNumber" }); cboSortSearch.SelectedIndex = 0; dgvInstruments.AutoGenerateColumns = false; dgvInstruments.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; switch (FormMode) { case FormMode.Edit: dgvInstruments.ReadOnly = false; DataGridViewTextBoxColumn objProcedureColumn = new DataGridViewTextBoxColumn { HeaderText = "Procedure", Name = "txtProcedureColumn", DataPropertyName = "Procedure" }; dgvInstruments.Columns.Insert(8, objProcedureColumn); DataGridViewCheckBoxColumn objOutOfServiceColumn = new DataGridViewCheckBoxColumn { HeaderText = "Out Of Service", Name = "chkOutOfServiceColumn", DataPropertyName = "OutOfService" }; dgvInstruments.Columns.Insert(9, objOutOfServiceColumn); CalendarColumn objOutOfServiceDateColumn = new CalendarColumn { HeaderText = "Out Of Service Date", Name = "dtpOutOfServiceDateColumn", DataPropertyName = "OutOfServiceDate", SortMode = DataGridViewColumnSortMode.Automatic }; dgvInstruments.Columns.Insert(10, objOutOfServiceDateColumn); this.WindowState = FormWindowState.Maximized; db = new CalibrationDb(); break; case FormMode.Select: btnSave.Visible = false; btnRefresh.Visible = false; dgvInstruments.ReadOnly = true; break; } db.Instruments.Load(); GetInstruments(); }
private bool DesignTableStyle(ref string strErrMsg) { try { string m_strMaskCols = "", m_strShowCols = ""; this.AutoGenerateColumns = false; this.DataSource = dtSource; this.EditingControlShowing -= new DataGridViewEditingControlShowingEventHandler(clsSearchGrid_EditingControlShowing); ////**** If the Default design is false then setting Colors for that Grid this.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(clsSearchGrid_EditingControlShowing); //this.ColumnHeadersDefaultCellStyle.BackColor=System.Drawing.Color.Lavender; //this.ColumnHeadersDefaultCellStyle.ForeColor = System.Drawing.Color.Navy; //this.GridColor=System.Drawing.Color.Silver; if (this.Columns.Count > 0) { this.Columns.Clear(); } for(int i=0; i < dtSource.Columns.Count; i++) { int local0 = 0; if (strColNames[i].ToUpper().IndexOf("MASK") == 0) continue; if (CheckComboBoxColumn(i)) { DataGridViewComboBoxColumn dgCBCol = new DataGridViewComboBoxColumn(); //dgCBCol.HeaderText = dtSource.Columns[i].ColumnName; dgCBCol.HeaderText = strHeadings[i]; dgCBCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgCBCol.DataSource = GetComboValue(i); //dgCBCol.DefaultCellStyle.NullValue = "Choose a value"; dgCBCol.Width = 200; dgCBCol.DisplayStyleForCurrentCellOnly = true; //comboforall = new ComboBox(); if (CheckReadOnlyColumn(i)) { dgCBCol.ReadOnly = true; } this.Columns.Insert(this.Columns.Count, dgCBCol); } else if (CheckCheckBoxColumn(i)) { DataGridViewCheckBoxColumn dgChkCol = new DataGridViewCheckBoxColumn(false); if (dgChkCol.Displayed) { } else { dgChkCol.Visible = true; } dgChkCol.HeaderText = strHeadings[i]; dgChkCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgChkCol.CellTemplate = new DataGridViewCheckBoxCell(); //this.CellClick += new DataGridViewCellEventHandler(clsWritableGrid_CellClick); // this.CurrentCellDirtyStateChanged += new EventHandler(clsWritableGrid_CurrentCellDirtyStateChanged); this.CellContentClick += new DataGridViewCellEventHandler(clsWritableGrid_CellContentClick); this.Columns.Add(dgChkCol); //for (int j = 0; j < dtSource.Rows.Count; j++) //{ // dgChkCol.CellTemplate.Selected = true; //} } else if (CheckDateTimeColumn(i)) { CalendarColumn dgDTPCol = new CalendarColumn(); dgDTPCol.HeaderText = strHeadings[i]; dgDTPCol.DataPropertyName = dtSource.Columns[i].ColumnName; if (CheckReadOnlyColumn(i)) { dgDTPCol.ReadOnly = true; } this.Columns.Add(dgDTPCol); } else if (CheckButtonColumn(i)) { DataGridViewButtonColumn dgBtnCol = new DataGridViewButtonColumn(); dgBtnCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgBtnCol.HeaderText = strHeadings[i]; this.Columns.Add(dgBtnCol); } else { DataGridViewTextBoxColumn dgTBCol = new DataGridViewTextBoxColumn(); dgTBCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgTBCol.HeaderText = strHeadings[i]; if (CheckReadOnlyColumn(i)) { dgTBCol.ReadOnly = true; } if (CheckRightAlignColumn(i)) { //dgTBCol.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight; dgTBCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; //dgTBCol.DataGridView.AlternatingRowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } else { //dgTBCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; //dgTBCol.DataGridView.AlternatingRowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft; } if (CheckNumericColumn(i, ref local0)) { dgTBCol.DefaultCellStyle.Format = "N" +arlNumericColFloatSize[local0]; CultureInfo inf = new CultureInfo(CultureInfo.CurrentCulture.LCID, true); inf.NumberFormat.NumberGroupSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator; inf.NumberFormat.NumberDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; dgTBCol.DefaultCellStyle.FormatProvider = inf; //dgTBCol.DefaultCellStyle.Format = "F2"; ////dgTBCol.deDefaultCellStyle.NullValue = 0.00; ////this[this.CurrentRowIndex, i].DefaultValue = 0.00; //*** if ((Boolean)arlFixedLengthNumCols[local0]) { dgTBCol.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dgTBCol.MaxInputLength = 21; dgTBCol.MinimumWidth = 115; dgTBCol.Width = 115; //dgTBCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.NotSet; } ////**** } else { //dgTBCol.Width = 200; //dgTBCol.Resizable = DataGridViewTriState.False; //dgTBCol.TextType = clsTxtBox.TypeEnum.String; //dgTBCol.TextBox.MaxLength = getMaxStrLength(i); //dgTBCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader; } //dgTBCol.SortMode = DataGridViewColumnSortMode.NotSortable; this.Columns.Insert(this.Columns.Count, dgTBCol); } //this.Columns[i].HeaderText = strHeadings[i]; } //#region changing for ColSizing //for (int k = 0; k < this.Columns.Count; k++) //{ // this.Columns[k].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; //} this.Font = new Font(this.Font, FontStyle.Regular); this.Invalidate(); this.Refresh(); return true; } catch(Exception ex) { strErrMsg = ex.Source + " - " + ex.Message; return false; } }
private void Form1_Load(object sender, EventArgs e) { //日历 CalendarColumn col = new CalendarColumn(); col.HeaderText = "计划日期"; //this.dataGridView1.Columns.Add(col); this.dataGridView1.Columns.Insert(2, col); // Read Data List<string> lst = ReadFile(); // Insert dataGridView List<WorkLogData> dataList = ConvertList(lst); InsertToList(dataList); readTxt(); this.WindowState = FormWindowState.Maximized; dataGridView1.RowsAdded += dataGridView1_RowsAdded; Remind(); foreach (DataGridViewColumn item in dataGridView1.Columns) { dataGridView1.Columns[item.Name].SortMode = DataGridViewColumnSortMode.Programmatic; } }
public void SetDataBinding(object datasource,string dataMember) { try { DataTable dtset = (DataTable)datasource; this.DataSource = dtset; dvSource = dtset.DefaultView;//Debanjan Added Because Filters Were Not Working After Removing Filter With Data Added But Not Saved. this.Columns.Clear(); for (int i = 0; i < dtset.Columns.Count; i++) { if (dtset.Columns[i].ColumnName.ToUpper().IndexOf("MASK") == 0) continue; if (CheckComboBoxColumn(i)) { DataGridViewComboBoxColumn dgCBCol = new DataGridViewComboBoxColumn(); dgCBCol.HeaderText = dtSource.Columns[i].ColumnName; dgCBCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgCBCol.DataSource = GetComboValue(i); dgCBCol.DefaultCellStyle.NullValue = "Choose a value"; dgCBCol.Width = 200; dgCBCol.DisplayStyleForCurrentCellOnly = true; //comboforall = new ComboBox(); if (CheckReadOnlyColumn(i)) { dgCBCol.ReadOnly = true; } this.Columns.Insert(this.Columns.Count, dgCBCol); } else if (CheckCheckBoxColumn(i)) { DataGridViewCheckBoxColumn dgChkCol = new DataGridViewCheckBoxColumn(false); if (dgChkCol.Displayed) { } else { dgChkCol.Visible = true; } dgChkCol.HeaderText = strHeadings[i]; dgChkCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgChkCol.CellTemplate = new DataGridViewCheckBoxCell(); this.Columns.Add(dgChkCol); } else if (CheckDateTimeColumn(i)) { CalendarColumn dgDTPCol = new CalendarColumn(); dgDTPCol.HeaderText = strHeadings[i]; dgDTPCol.DataPropertyName = dtSource.Columns[i].ColumnName; if (CheckReadOnlyColumn(i)) { dgDTPCol.ReadOnly = true; } this.Columns.Add(dgDTPCol); } else if (CheckButtonColumn(i)) { DataGridViewButtonColumn dgBtnCol = new DataGridViewButtonColumn(); dgBtnCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgBtnCol.HeaderText = strHeadings[i]; this.Columns.Add(dgBtnCol); } else { DataGridViewTextBoxColumn dgTBCol = new DataGridViewTextBoxColumn(); dgTBCol.DataPropertyName = dtSource.Columns[i].ColumnName; dgTBCol.HeaderText = strHeadings[i]; this.Columns.Insert(this.Columns.Count, dgTBCol); if (CheckReadOnlyColumn(i)) { dgTBCol.ReadOnly = true; } if (CheckRightAlignColumn(i)) dgTBCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; } //#region changing for ColSizing for (int k = 0; k < this.Columns.Count; k++) { this.Columns[k].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } this.Font = new Font(this.Font, FontStyle.Regular); } if (this.AssociatedSearchGrid != null) { this.AssociatedSearchGrid.dtFullData = dtset; } CurrencyManager cm = (CurrencyManager)this.BindingContext[this.DataSource]; ((DataView)cm.List).AllowNew = false; DoCreateFilterHeaders();//Debanjan Added Because Filters Were Not Coming After This Method Is Called. } catch (Exception ex) { MessageBox.Show(""); } }