public Form1() { InitializeComponent(); // tell our form that we want to intercept all key press events in our form.Otherwise our KeyPress event method will only get events when the form class has focus. //this.KeyPreview = true; //give our dataGrid our SIP, so that I can listen and react to events on our SIP editableDataGrid1.SIP = inputPanel1; editableDataGrid1.CellValidating += new EditableDataGridCellValidatingEventHandler(editableDataGrid1_CellValidating); editableDataGrid1.CellValueChanged += new EditableDataGridCellValueChangedEventHandler(editableDataGrid1_CellValueChanged); buttonPanel1.Text = "something"; ////allow new rows on datagrid //editableDataGrid1.AllowNewRow = true; //set up columns for our dataGrid DataGridTableStyle ts = new DataGridTableStyle() { MappingName = "something" }; comboBoxCol = new EditableComboBoxColumn() { MappingName = "num1" }; textBoxCol = new EditableTextBoxColumn() { MappingName = "word", MaxTextLength = 12, GoToNextColumnWhenTextCompleate = true }; dateTimeCol = new EditableDateTimePickerColumn() { MappingName = "date" }; upDwnCol = new EditableUpDownColumn() { MappingName = "upDwn" }; ts.GridColumnStyles.Add(comboBoxCol); ts.GridColumnStyles.Add(textBoxCol); ts.GridColumnStyles.Add(dateTimeCol); ts.GridColumnStyles.Add(upDwnCol); //set up our button column and give it a event handler for button clicks //note the mapping name for the buttonColumn must be provided and a valid property to bind to //this is because the dataGrid only displays columns that have a valid MappingName //I've created a work around that should work for Full Framework, and will probably be able to make a workaround for Mobile //, but until then provide a mapping name. //For DAL DataObjects you could use the Tag property as a mapping name, since it isn't reserved for any propuse, and is intended for special cases like this. DataGridButtonColumn buttonCol = new DataGridButtonColumn() { MappingName = "button", UseCellColumnTextForCellValue = true, Text = "click me" }; buttonCol.Click += new ButtonCellClickEventHandler(buttonCol_Click); ts.GridColumnStyles.Add(buttonCol); editableDataGrid1.TableStyles.Add(ts); //create some dummy data to test the grid List<something> things = new List<something>(); for (int i = 0; i < 100; i++) { things.Add(new something() { num1 = i, word = "word", button = "click me" }); } bindingSource1.DataSource = things; //editableDataGrid1.DataSource = things; }
public ControlTreeDataGrid(IApplicationController controller, FormDataEntryLogic dataEntryController, InputPanel sip) { this.Controller = controller; this.DataEntryController = dataEntryController; DataGridAdjuster.InitializeGrid(this); DataGridTableStyle tableStyle = DataEntryController.Unit.InitializeTreeColumns(this); this.AllowUserToAddRows = false;//don't allow down arrow to add tree this.SIP = sip; //this.Font = new System.Drawing.Font("Courier New", 12F, System.Drawing.FontStyle.Bold); //initialize _BS_trees this._BS_trees = new System.Windows.Forms.BindingSource(); ((System.ComponentModel.ISupportInitialize)(this._BS_trees)).BeginInit(); this._BS_trees.DataSource = typeof(TreeVM); this._BS_trees.CurrentChanged += new EventHandler(_BS_trees_CurrentChanged); this.DataSource = this._BS_trees; ((System.ComponentModel.ISupportInitialize)(this._BS_trees)).EndInit(); _speciesColumn = tableStyle.GridColumnStyles["TreeDefaultValue"] as EditableComboBoxColumn; _sgColumn = tableStyle.GridColumnStyles["SampleGroup"] as EditableComboBoxColumn; _stratumColumn = tableStyle.GridColumnStyles["Stratum"] as EditableComboBoxColumn; _treeNumberColumn = tableStyle.GridColumnStyles["TreeNumber"] as EditableTextBoxColumn; _initialsColoumn = tableStyle.GridColumnStyles["Initials"] as EditableComboBoxColumn; _logsColumn = tableStyle.GridColumnStyles["LogCountActual"] as DataGridButtonColumn; _kpiColumn = tableStyle.GridColumnStyles["KPI"] as EditableTextBoxColumn; _errorsColumn = tableStyle.GridColumnStyles["Errors"] as DataGridTextBoxColumn; if (_logsColumn != null) { _logsColumn.Click += this.LogsClicked; } if (_initialsColoumn != null) { _initialsColoumn.DataSource = this.Controller.Settings.Cruisers.ToArray(); } }
public static DataGridTableStyle InitializeTreeColumns(this ITreeFieldProvider provider, EditableDataGrid grid) { DataGridTableStyle tblStyle = new System.Windows.Forms.DataGridTableStyle() { MappingName = "TreeVM" }; int screenWidth = Screen.PrimaryScreen.WorkingArea.Width; int charWidth = MeasureTextWidth(grid, "0"); // Loop through each item in the fields list, // set up a column style and add it to the table style. foreach (TreeFieldSetupDO field in provider.TreeFields) { CustomColumnBase col; switch (field.Field) { case "CuttingUnit": { continue; } case "Species": { col = new FMSC.Controls.EditableComboBoxColumn(); ((EditableComboBoxColumn)col).DisplayMember = "Species"; //((EditableComboBoxColumn)col).ValueMember = "Self"; col.MappingName = "TreeDefaultValue"; col.Format = "[Species]"; break; } case "CountOrMeasure": { col = new FMSC.Controls.EditableComboBoxColumn(); //((EditableComboBoxColumn)col).DisplayMember = "CountOrMeasure"; //((EditableComboBoxColumn)col).ValueMember = "CountOrMeasure"; ((EditableComboBoxColumn)col).DataSource = new string[] { "C", "M", "I" }; break; } case "LiveDead": { col = new FMSC.Controls.EditableComboBoxColumn(); //((EditableComboBoxColumn)col).DisplayMember = "LiveDead"; //((EditableComboBoxColumn)col).ValueMember = "LiveDead"; ((EditableComboBoxColumn)col).DataSource = new string[] { "L", "D" }; break; } case "Stratum": { col = new FMSC.Controls.EditableComboBoxColumn(); ((EditableComboBoxColumn)col).DisplayMember = "Code"; //((EditableComboBoxColumn)col).ValueMember = "Code"; break; } case "SampleGroup": { col = new FMSC.Controls.EditableComboBoxColumn(); ((EditableComboBoxColumn)col).DisplayMember = "Code"; //((EditableComboBoxColumn)col).ValueMember = "Code"; break; } case "KPI": { col = MakeColumn(field.ColumnType); //col.ReadOnly = true; break; } case "Initials": { col = new FMSC.Controls.EditableComboBoxColumn(); ((EditableComboBoxColumn)col).DisplayMember = "Initials"; ((EditableComboBoxColumn)col).ValueMember = "Initials"; break; } default://all other columns { col = MakeColumn(field.ColumnType); break; } } // Set up width: autowidth or fixed width if (field.Width == 0.0) { col.Width = MeasureTextWidth(grid, field.Heading.Trim()) + 18;//plus 18 to allow for padding } else { int width1 = (int)field.Width; if (width1 <= 10) { int width2 = (charWidth * width1) + 18; col.Width = Math.Min(screenWidth, width2); } else { col.Width = Math.Min(screenWidth, width1); } } if (String.IsNullOrEmpty(col.MappingName)) //see if we have already set the Mapping Name { col.MappingName = field.Field; } if (String.IsNullOrEmpty(col.HeaderText)) { col.HeaderText = field.Heading; } if (string.IsNullOrEmpty(col.Format)) { col.Format = field.Format; // 'C' = currency, 'N' = number (E.G. "N1" means one decimal place), #0.00 } col.FormatInfo = null; //this.myCustomColumnBase.Width = (int)myTreeFieldSetups[i].Width; col.NullText = String.Empty;// <- look into this // Add the column style to the table style tblStyle.GridColumnStyles.Add(col); } DataGridButtonColumn logsCol = new DataGridButtonColumn(); logsCol.HeaderText = "Logs"; logsCol.MappingName = "LogCountActual"; tblStyle.GridColumnStyles.Add(logsCol); tblStyle.GridColumnStyles.Add(MakeErrorColumn(screenWidth)); // Add the newly created DataGridTableStyle to the grid. grid.TableStyles.Add(tblStyle); return tblStyle; }
public LayoutPlot(FormDataEntryLogic dataEntryController, Control parent, PlotStratum stratum, InputPanel sip) { Stratum = stratum; this.ViewLogicController = new LayoutPlotLogic(stratum, this, dataEntryController, dataEntryController.ViewController); InitializeComponent(); InitializePlotNavIcons(); //Setup Plot Nav Bar this._addPlotButton.Text = "+"; this._deletePlotButton.Text = "-"; this._plotInfoButton.Text = "i"; this._expandGridButton.ImageIndex = 0; this._expandGridButton.ButtonImageLayout = ImageLayout.Tile; this._nextPlotButton.ButtonImageLayout = ImageLayout.Zoom; this._gotoLastPlotButton.ButtonImageLayout = ImageLayout.Zoom; this._prevPlotButton.ButtonImageLayout = ImageLayout.Zoom; this._gotoFirstPlotButton.ButtonImageLayout = ImageLayout.Zoom; if (ViewController.PlatformType == PlatformType.WinCE) { this._expandGridButton.Font = new System.Drawing.Font("Arial", this._expandGridButton.Font.Size, this._expandGridButton.Font.Style); this._gotoFirstPlotButton.Font = new System.Drawing.Font("Arial", this._gotoFirstPlotButton.Font.Size, this._gotoFirstPlotButton.Font.Style); this._gotoLastPlotButton.Font = new System.Drawing.Font("Arial", this._gotoLastPlotButton.Font.Size, this._gotoLastPlotButton.Font.Style); this._nextPlotButton.Font = new System.Drawing.Font("Arial", this._nextPlotButton.Font.Size, this._nextPlotButton.Font.Style); this._prevPlotButton.Font = new System.Drawing.Font("Arial", this._prevPlotButton.Font.Size, this._prevPlotButton.Font.Style); } //Setup DataGrid DataGridAdjuster.InitializeGrid(this._dataGrid); _tableStyle = stratum.InitializeTreeColumns(_dataGrid); this._dataGrid.SIP = sip; this._dataGrid.CellValidating += new EditableDataGridCellValidatingEventHandler(_dataGrid_CellValidating); this._dataGrid.CellValueChanged += new EditableDataGridCellValueChangedEventHandler(this._dataGrid_CellValueChanged); //this._dataGrid.DataSource = typeof(FSCruiserV2.Logic.TreeVM);//_BS_Trees; this._dataGrid.Click += new EventHandler(_dataGrid_Click); this._dataGrid.ReadOnly = true; this._dataGrid.AllowUserToAddRows = false; _speciesColumn = _tableStyle.GridColumnStyles["TreeDefaultValue"] as EditableComboBoxColumn; _sgColumn = _tableStyle.GridColumnStyles["SampleGroup"] as EditableComboBoxColumn; _treeNumberColumn = _tableStyle.GridColumnStyles["TreeNumber"] as EditableTextBoxColumn; _initialsColoumn = _tableStyle.GridColumnStyles["Initials"] as EditableComboBoxColumn; _logsColumn = _tableStyle.GridColumnStyles["LogCountActual"] as DataGridButtonColumn; _kpiColumn = _tableStyle.GridColumnStyles["KPI"] as EditableTextBoxColumn; _errorsColumn = _tableStyle.GridColumnStyles["Error"] as DataGridTextBoxColumn; if (_logsColumn != null) { _logsColumn.Click += this.LogsClicked; } HandleCruisersChanged(); this.Dock = DockStyle.Fill; this.Parent = parent; InitializeTallyPanel(); this.ViewLogicController.UpdateCurrentPlot(); }