public static void InitializeGrid(EditableDataGrid grid)
 {
     // Default grid-level parameters
     grid.RowHeadersVisible = false;
     //grid.HomeColumnIndex = 0;
     //preferredRowHeight = 20;
     grid.Font                 = new Font("Courier New", 12.0F, FontStyle.Regular);
     grid.ForeColor            = Color.Black;
     grid.GridLineColor        = Color.Black;
     grid.ErrorColor           = Color.Red;
     grid.BackColor            = Color.White; // background color of the actual grid cells
     grid.BackgroundColor      = Color.Black; // background color of the control, but outside the grid.
     grid.HeaderBackColor      = Color.DarkGray;
     grid.HeaderForeColor      = Color.White;
     grid.SelectionBackColor   = Color.Yellow;
     grid.SelectionForeColor   = Color.Black;
     grid.AlternatingBackColor = Color.LightGray;
 }
        public static DataGridTableStyle InitializeTreeColumns(this ITreeFieldProvider provider, EditableDataGrid grid)
        {
            DataGridTableStyle tblStyle = new System.Windows.Forms.DataGridTableStyle()
            {
                MappingName = "Tree"
            };

            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)
            {
                DataGridTextBoxColumn col;

                switch (field.Field)
                {
                case "CuttingUnit":
                {
                    continue;
                }

                case "Species":
                {
                    col = new FMSC.Controls.EditableComboBoxColumn()
                    {
                        DisplayMember = "Species",
                        //((EditableComboBoxColumn)col).ValueMember = "Self";
                        MappingName = "TreeDefaultValue",
                        Format      = "[Species]"
                    };
                    break;
                }

                case "CountOrMeasure":
                {
                    col = new FMSC.Controls.EditableComboBoxColumn()
                    {
                        //((EditableComboBoxColumn)col).DisplayMember = "CountOrMeasure";
                        //((EditableComboBoxColumn)col).ValueMember = "CountOrMeasure";
                        DataSource = new string[] { "C", "M", "I" }
                    };
                    break;
                }

                case "LiveDead":
                {
                    col = new FMSC.Controls.EditableComboBoxColumn()
                    {
                        //((EditableComboBoxColumn)col).DisplayMember = "LiveDead";
                        //((EditableComboBoxColumn)col).ValueMember = "LiveDead";
                        DataSource = new string[] { "L", "D" }
                    };
                    break;
                }

                case "Stratum":
                {
                    if (provider is PlotStratum)
                    {
                        col = new DataGridTextBoxColumn();
                    }
                    else
                    {
                        col = new FMSC.Controls.EditableComboBoxColumn()
                        {
                            DisplayMember = "Code"
                                            //((EditableComboBoxColumn)col).ValueMember = "Code";
                        };
                    }
                    break;
                }

                case "SampleGroup":
                {
                    col = new FMSC.Controls.EditableComboBoxColumn()
                    {
                        DisplayMember = "Code"
                                        //((EditableComboBoxColumn)col).ValueMember = "Code";
                    };
                    break;
                }

                case "KPI":
                {
                    col = MakeColumn(field.ColumnType);
                    //col.ReadOnly = true;
                    break;
                }

                case "Initials":
                {
                    col = new FMSC.Controls.EditableComboBoxColumn()
                    {
                        DisplayMember = "Initials",
                        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";
            logsCol.Width       = MeasureTextWidth(grid, logsCol.HeaderText) + 18;//plus 18 to allow for padding
            tblStyle.GridColumnStyles.Add(logsCol);

            tblStyle.GridColumnStyles.Add(MakeErrorColumn(screenWidth));
            // Add the newly created DataGridTableStyle to the grid.
            grid.TableStyles.Add(tblStyle);

            return(tblStyle);
        }
        public static DataGridTableStyle InitializeLogColumns(this ILogFieldProvider stratum, EditableDataGrid grid)
        {
            DataGridTableStyle tblStyle = new DataGridTableStyle();

            tblStyle.MappingName = "Log";

            foreach (LogFieldSetupDO field in stratum.LogFields)
            {
                DataGridTextBoxColumn col = MakeColumn(field.ColumnType);
                col.MappingName = field.Field;
                col.HeaderText  = field.Heading;
                col.Format      = field.Format; // 'C' = currency, 'N' = number (E.G. "N1" means one decimal place), #0.00
                col.FormatInfo  = null;
                col.NullText    = String.Empty; // <- look into this

                if (field.Width == 0.0)
                {
                    col.Width = MeasureTextWidth(grid, field.Heading.Trim()) + 18;//plus 18 to allow for padding
                }
                else
                {
                    col.Width = (int)field.Width;
                }

                tblStyle.GridColumnStyles.Add(col);
            }

            tblStyle.GridColumnStyles.Add(MakeErrorColumn(Screen.PrimaryScreen.WorkingArea.Width));

            grid.TableStyles.Add(tblStyle);

            return(tblStyle);
        }