Example #1
0
        private void ck_Column3_ShowNullWhenZero_CheckedChanged(object sender, EventArgs e)
        {
            if (dataGridView1.Columns.Count < 3)
            {
                return;
            }

            TNumEditDataGridViewColumn column = dataGridView1.Columns[2] as TNumEditDataGridViewColumn;

            if (column != null)
            {
                column.ShowNullWhenZero = ck_Column3_ShowNullWhenZero.Checked;
            }
        }
Example #2
0
        private void cb_Column3_DecimalLength_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (dataGridView1.Columns.Count < 3)
            {
                return;
            }

            TNumEditDataGridViewColumn column = dataGridView1.Columns[2] as TNumEditDataGridViewColumn;

            if (column != null)
            {
                column.DecimalLength = cb_Column3_DecimalLength.SelectedIndex;
            }
        }
        // Grid Setting End



        // Start Grid Setting With ComboBox
        // Grid Header Setting Start
        // 1- Grid View Control               Control
        // 2- Total Number of Col             Total Columns for cross check 
        // 3- Column Headers                  Comma Seperated String
        // 4- Column Width                    Comma Seperated String
        // 5- Column Min Width                Column Minimum Width Comma Seperated String
        // 6- Col Max Input                   Maximum number of Characters 0 = No limit
        // 7- Col Format                      T = Text, H = Hidden, TI = Text Integer, N2 = Numeric 2 digit
        //                                    CB = ComboBox Column , MT Masked Text Box                                   
        // 8- Col Readonly                    1 = Readonly, 0 = Read/Write (Single 1 = all readonly, Single 0 All Read/Write)
        // 9- Grid Type                       Data = Input, Otherwise Lookup Grid
        // 10- MaskedEditBox Mask List         Default = null

        // 11- Grid Combo Fill Type List      Q = QRY, T = Table List DEfault = null
        // 12- Grid Combo TableKeyField List  Table Name, KeyField Name, bool Set Default, Default = null
        // 13- Grid Combo Query List          Default = null
        // 14- Grid Color Scheme              1 = Default , 0 = Custom
        // 
        #region SetGridHeaderCmb

        public static void SetGridHeaderCmb(
            DataGridView DGV1,
            int pColTotal,
            string pColHeader,
            string pColWidth,
            string pColMinWidth,
            string pColMaxInputLen,
            string pColFormat,
            string pColReadyOnly,
            string pGridType,
            List<string> pMtMask = null,
            List<string> pCmbFillType = null,
            List<string> pCmbTableKeyfield = null,
            List<string> pCmbQry = null,
            bool AllowUserToAddRow = false,
            int pGridColorScheme = 1)
        {
            //             DataGridViewComboBoxColumn pCmb,

            int widM = 10;     // Multiple for Character width
            string formatChar = string.Empty;
            //string fColFormat = pColFormat;

            //#region Grid Color Scheme
            // Combo Box
            List<string> fCmbFillType = pCmbFillType;
            List<string> fCmbTableKeyfield = pCmbTableKeyfield;
            List<string> fCmbQry = pCmbQry;
            List<string> fMtMask = pMtMask;
            int fNoCbo = 0;
            int fNoMt = 0;
            //if (pCmbTableKeyfield.Count > 0)
            //{ 

            //}
            // Combo Box
            // Grid Color Scheme
            switch (pGridColorScheme)
            {
                case 1:
                    // Light Blue/Grey
                    DGV1.BackgroundColor = Color.FromArgb(193, 208, 222);
                    DGV1.GridColor = Color.FromArgb(102, 179, 64);
                    DGV1.DefaultCellStyle.BackColor = Color.FromArgb(193, 208, 222);
                    //DGV1.AutoResizeColumnHeadersHeight(30); //= AutoSizeMode.GrowAndShrink;
                    break;
                case 2:
                    //
                    DGV1.BackgroundColor = Color.FromArgb(255, 255, 192);
                    DGV1.GridColor = Color.FromArgb(214, 10, 46);
                    DGV1.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 192);
                    break;
            }

            //#endregion

            try
            {
                //#region Prepare Column Strings and Arrays

                // Prepare Column Strings and Arrays 
                if (DGV1.RowCount == 0)
                {
                    //DGV1.RowCount = 1;
                }

                // Column Headers
                string[] ColHeaderArr = pColHeader.Split(',');

                // Grid headerWidth 
                if (pColWidth.Trim().Length == 0)
                {
                    pColWidth = StrRepeate("10", pColTotal);
                    if (pColWidth == "Err")
                    {
                        // Reaise Error
                    }
                }
                string[] ColWidthArr = pColWidth.Split(',');

                // Column Min Width
                string[] ColMinWidthArr;
                if (pColMinWidth.Trim().Length == 0)
                {
                    pColMinWidth = StrRepeate("0", pColTotal);
                    if (pColMinWidth == "Err")
                    {
                        // Reaise Error
                    }
                    ColMinWidthArr = pColMinWidth.Split(',');
                }
                else
                {
                    ColMinWidthArr = pColMinWidth.Split(',');
                }


                // Column Max Input Length
                string[] ColMaxInputLenArr;
                if (pColMaxInputLen.Trim().Length == 0)
                {
                    pColMaxInputLen = StrRepeate("0", pColTotal);
                    if (pColMaxInputLen == "Err")
                    {
                        // Reaise Error
                    }
                    ColMaxInputLenArr = pColMaxInputLen.Split(',');
                }
                else
                {
                    ColMaxInputLenArr = pColMaxInputLen.Split(',');
                }
                // Column Format
                if (pColFormat.Trim().Length == 0)
                {
                    pColFormat = StrRepeate("T", pColTotal);
                    if (pColFormat == "Err")
                    {
                        // Reaise Error
                    }

                }
                string[] ColFormatArr = pColFormat.Split(',');
                if (ColFormatArr.Length > 0)
                {
                    for (int i = 0; i < ColFormatArr.Length; i++)
                    {
                        if (ColFormatArr[i].Trim() == "CB")
                        {
                            if (fCmbFillType == null || fCmbTableKeyfield == null || fCmbQry == null)
                            {
                                MessageBox.Show("Grid Combo Box, data insufficient, check data behind combo box and try again " + DGV1.Name.ToString(), "CB null: Grid Header");
                                return;
                            }
                            else
                            {
                                if (fCmbTableKeyfield.Count == 0)
                                {
                                    MessageBox.Show("Grid Combo Box, data insufficient, check data behind combo box and try again " + DGV1.Name.ToString(), "CB Empty: Grid Header");
                                    return;
                                }
                            }
                        } // if CB
                    } // for
                } // if
                else
                {
                    MessageBox.Show("Grid Format data insufficient, check format try again " + DGV1.Name.ToString(), "Column Format Empty: Grid Header");
                    return;
                }

                // Column Width
                if (pColWidth.Trim().Length == 0)
                {
                    pColWidth = StrRepeate("10", pColTotal);
                    if (pColWidth == "Err")
                    {
                        // Reaise Error
                    }
                }
                // Column ReadOnly
                if (pColReadyOnly.Trim().Length == 0)
                {
                    // 1 = ReadOnly, 0 = Read/Write 
                    pColReadyOnly = StrRepeate("1", pColTotal);
                    if (pColWidth == "Err")
                    {
                        // Reaise Error
                    }
                }
                else
                {
                    if (pColReadyOnly.Trim() == "1")
                    {
                        // All Read Only
                        pColReadyOnly = StrRepeate("1", pColTotal);
                        if (pColWidth == "Err")
                        {
                            // Reaise Error
                        }

                    }
                    else if (pColReadyOnly.Trim() == "0")
                    {
                        // All Read/Write
                        pColReadyOnly = StrRepeate("0", pColTotal);
                        if (pColWidth == "Err")
                        {
                            // Reaise Error
                        }
                    }
                }


                string[] ColReadyOnlyArr = pColReadyOnly.Split(',');
                // Check Lengths are same as ColumnTotal
                if (
                    ColHeaderArr.Count() != pColTotal ||
                    ColWidthArr.Count() != pColTotal ||
                    ColMaxInputLenArr.Count() != pColTotal ||
                    ColFormatArr.Count() != pColTotal ||
                    ColReadyOnlyArr.Count() != pColTotal ||
                    ColMinWidthArr.Count() != pColTotal
                  )
                {
                    MessageBox.Show("Array Length Conflict. See Debug Info:>>> " + DGV1.Name.ToString(), "Parameters & Column Totals: Grid Header");
                    return;
                }

                //#endregion Prepare Column Strings and Arrays

                //#region Column Create

                if (pGridType == "DATA")
                {
                    //#region Data Grid
                    // Create Columns: Assign Column Properties
                    for (int i = 0; i < pColTotal; i++)
                    {
                        switch (ColFormatArr[i].Trim())
                        {
                            case "T":
                            case "TB":
                            case "H":
                            case "TBH":
                            case "TI":
                                {
                                    // T = Text
                                    // H = Hidden Text
                                    // TI = Text Box Integer
                                    var col4 = new DataGridViewTextBoxColumn();
                                    col4.Name = "Column4" + i.ToString();
                                    if (Convert.ToInt32(ColMaxInputLenArr[i].Trim()) != 0)
                                    {
                                        col4.MaxInputLength = Convert.ToInt32(ColMaxInputLenArr[i].Trim());
                                    }
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }
                            case "N0":
                                {
                                    // Numeric 0 digit
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 0;
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (Convert.ToInt32(ColMaxInputLenArr[i].Trim()) != 0)
                                    {
                                        col4.MaxInputLength = Convert.ToInt32(ColMaxInputLenArr[i].Trim());
                                    }

                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }
                            case "N2":
                                {
                                    // Numeric 2 digit
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 2;
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (Convert.ToInt32(ColMaxInputLenArr[i].Trim()) != 0)
                                    {
                                        col4.MaxInputLength = Convert.ToInt32(ColMaxInputLenArr[i].Trim());
                                    }

                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }

                            case "N3":
                                {
                                    // Numeric 3 digit
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 3;
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (Convert.ToInt32(ColMaxInputLenArr[i].Trim()) != 0)
                                    {
                                        col4.MaxInputLength = Convert.ToInt32(ColMaxInputLenArr[i].Trim());
                                    }
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }

                            case "N4":
                                {
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 4;
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (Convert.ToInt32(ColMaxInputLenArr[i].Trim()) != 0)
                                    {
                                        col4.MaxInputLength = Convert.ToInt32(ColMaxInputLenArr[i].Trim());
                                    }
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }
                            case "CB":
                                {
                                    var col4 = new DataGridViewComboBoxColumn();
                                    // fNoCbo = Number of ComboBoxes
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (fCmbTableKeyfield[fNoCbo] == "")
                                    {
                                        MessageBox.Show("Combo Field List Empty. Connect and try again " + DGV1.Name.ToString(), "CB: Grid Header");
                                        return;
                                    }
                                    if (pCmbQry[fNoCbo] == "")
                                    {
                                        MessageBox.Show("Combo Qry List Empty. Connect and try again " + DGV1.Name.ToString(), "CB: Grid Header");
                                        return;
                                    }

                                    clsFillCombo.FillComboCol(
                                        col4,
                                        fCmbTableKeyfield[fNoCbo],
                                        pCmbQry[fNoCbo]
                                        );
                                    col4.DropDownWidth = 10;
                                    //col4.DropDownStyle = ComboBoxStyle.DropDownList;
                                    col4.DefaultCellStyle.Font = new Font("Tahoma", 10, FontStyle.Bold);
                                    //col4.DefaultCellStyle.ForeColor = Color.BlueViolet;
                                    col4.FlatStyle = FlatStyle.Flat;
                                    //var.Name = "ComboColumnSample";
                                    col4.HeaderText = "ComboColumnSample";
                                    //col4.DisplayMember = "Item";
                                    //col4.ValueMember = "Value";
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);

                                    fNoCbo++;
                                    break;
                                }
                            case "CH":
                                {
                                    var col4 = new DataGridViewCheckBoxColumn();
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }
                            case "MT":
                                {
                                    //mtbc = new MaskedTextBoxColumn();
                                    //mtbc.HeaderText = "Employee ID";
                                    //mtbc.Mask = "L00000";
                                    //mtbc.Width = 75;
                                    //this.employeesDataGridView.Columns.Add(mtbc);
                                    if (pMtMask[fNoMt] == "")
                                    {
                                        MessageBox.Show("MT Mask Empty. Connect and try again " + DGV1.Name.ToString(), "MT: Grid Header");
                                        return;
                                    }
                                    var col4 = new MaskedTextBoxColumn();
                                    col4.Name = "Column4" + i.ToString();
                                    col4.Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                    if (Convert.ToInt32(ColMinWidthArr[i].Trim()) > 0)
                                    {
                                        col4.MinimumWidth = widM * Convert.ToInt32(ColMinWidthArr[i].Trim());
                                    }
                                    col4.Mask = pMtMask[fNoMt];
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    fNoMt++;
                                    break;
                                }
                            default:
                                {
                                    MessageBox.Show("Grid Column Format Type unknown, Connect and try again " + DGV1.Name.ToString() + " Column Name :" + ColFormatArr[i].Trim(), "Column Format: Grid Header");
                                    return;
                                    //break;
                                }

                        } // End switch statement

                    } // end for create column
                    //#endregion
                }
                else
                {
                    //#region Lookup Grid

                    // Comented in old version: 2012 05 13 commented to implement TN
                    if (DGV1.ColumnCount < pColTotal)
                    {
                        DGV1.ColumnCount = pColTotal;
                    }

                    //#endregion LOOKUP GRID
                }

                //#endregion Create Columns

                //#region Column Allignment

                // Column Allignment and 
                for (int i = 0; i < pColTotal; i++)
                {

                    DGV1.Columns[i].HeaderText = ColHeaderArr[i].Trim();
                    DGV1.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

                    if (ColFormatArr[i].Trim() != "H")
                    {
                        DGV1.Columns[i].Width = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                    }
                    else
                    {
                        DGV1.Columns[i].Visible = false;
                    }
                    switch (ColFormatArr[i].Trim())
                    {
                        case "N0":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                //DGV1.Columns[i].ValueType = typeof(decimal);
                                //DGV1.Columns[i].DefaultCellStyle.Format = "N2";
                                break;
                            }

                        case "N2":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                DGV1.Columns[i].ValueType = typeof(decimal);
                                DGV1.Columns[i].DefaultCellStyle.Format = "N2";
                                break;
                            }
                        case "N3":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                DGV1.Columns[i].ValueType = typeof(decimal);
                                DGV1.Columns[i].DefaultCellStyle.Format = "N3";
                                break;
                            }
                        case "N4":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                DGV1.Columns[i].ValueType = typeof(decimal);
                                DGV1.Columns[i].DefaultCellStyle.Format = "N4";
                                break;
                            }
                        case "TI":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                break;
                            }
                        case "CB":
                            {
                                // Minimum Width
                                // DGV1.Columns[i].MinimumWidth = widM * Convert.ToInt32(ColWidthArr[i].Trim());
                                break;
                            }
                    }
                    switch (ColFormatArr[i].Trim())
                    {
                        case "C":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                                break;
                            }
                    } // end Switch statement

                } // End for loop
                //
                // Grid Level Settings
                //
                // Allow User to Add Row
                if (AllowUserToAddRow == false)
                {
                    DGV1.AllowUserToAddRows = false;
                }
                // Auto Size Last Column
                DGV1.Columns[pColTotal - 1].AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
                DGV1.RowHeadersVisible = false;                            // Headers at left hand side of the Grid
                //DGV1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
                // Fix Row Height 
                DGV1.AllowUserToResizeRows = false;
                //

        #endregion Column Allignment
                if (ColHeaderArr.Length != ColWidthArr.Length)
                {
                    MessageBox.Show("Warnning: Number of Header Titles and Header Width paramenters are not equal ...", "Set Grid Header");
                }


            }
            catch (Exception exp)
            {
                MessageBox.Show("Exception: " + exp.Message, "Grid Header Setting");
            }
        }
Example #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.Rows.Add(15);

            dataGridView1.Rows[1].Cells[1].Value = 12345;
            dataGridView1.Rows[2].Cells[1].Value = 0;

            dataGridView1.Rows[1].Cells[2].Value = -12345.123;
            dataGridView1.Rows[3].Cells[2].Value = 0;

            for (int k = 0; k < dataGridView1.Columns.Count; k++)
            {
                cb_ColNo.Items.Add(k.ToString());

                DataGridViewColumn column = dataGridView1.Columns[k];
                column.DataPropertyName = column.Name;

                if (column is TNumEditDataGridViewColumn)
                {
                    dt.Columns.Add(new DataColumn(column.Name, typeof(decimal)));
                }
                else
                {
                    dt.Columns.Add(new DataColumn(column.Name, typeof(string)));
                }
            }

            for (int k = 0; k < dataGridView1.Rows.Count; k++)
            {
                cb_RowNo.Items.Add(k.ToString());

                if ((k + 1) % 4 == 0)
                {
                    continue;
                }

                Random  rnd = new Random(k);
                DataRow dr  = dt.NewRow();
                for (int n = 0; n < dataGridView1.Columns.Count; n++)
                {
                    TNumEditDataGridViewColumn column = dataGridView1.Columns[n] as TNumEditDataGridViewColumn;
                    if (column != null)
                    {
                        double num = rnd.NextDouble() * 100;
                        if (column.AllowNegative)
                        {
                            num *= rnd.Next(2) - 1;
                        }
                        dr[n] = num;
                    }
                    else
                    {
                        dr[n] = "text" + (k + 1).ToString();
                    }
                }
                dt.Rows.Add(dr);
            }

            TNumEditDataGridViewColumn col = dataGridView1.Columns[1] as TNumEditDataGridViewColumn;

            cb_Column1_DecimalLength.Text       = col.DecimalLength.ToString();
            ck_Column1_ShowNullWhenZero.Checked = col.AllowNegative;

            col = dataGridView1.Columns[2] as TNumEditDataGridViewColumn;
            cb_Column3_DecimalLength.Text       = col.DecimalLength.ToString();
            ck_Column3_ShowNullWhenZero.Checked = col.AllowNegative;

            cb_RowNo.SelectedIndex = 1;
            cb_ColNo.SelectedIndex = 1;

            dataGridView1.CellEnter        += this.dataGridView1_CellEnter;
            dataGridView1.CellValueChanged += this.dataGridView1_CellEnter;

            dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[1];
        }
        // Fill ListView End

        // Grid Header Setting Start
        // 1- Grid View Control
        // 2- Total Number of Col           Total Columns for cross check 
        // 3- Column Headers                Comma Seperated String
        // 4- Column Width                  Comma Seperated String
        // 5- Col Max Input                 Maximum number of Characters 0 = No limit
        // 6- Col Format                    T = Text, H = Hidden, TI = Text Integer, N2 = Numeric 2 digit, MT = Masked Text Box
        //                                  CB = ComboBox Column                                    
        // 7- Col Readonly                  1 = Readonly, 0 = Read/Write (Single 1 = all readonly, Single 0 All Read/Write)
        // 8- Grid Type                     Data = Input, Otherwise Lookup Grid
        // 9- Grid Color Scheme             1 = Default , 0 = Custom
        // 
        public static void SetGridHeader(DataGridView DGV1,
            int pColTotal,
            string pColHeader,
            string pColWidth,
            string pColMaxInputLen,
            string pColFormat,
            string pColReadyOnly,
            string pGridType,
            int pGridColorScheme = 1)
        {
            int widM = 10;     // Multiple for Character width
            string formatChar = string.Empty;

            #region Grid Color Scheme

            // Grid Color Scheme
            switch (pGridColorScheme)
            {
                case 1:
                    // Light Blue/Grey
                    //DGV1.BackgroundColor = Color.FromArgb(193, 208, 222);
                    //DGV1.GridColor = Color.FromArgb(102, 179, 64);
                    //DGV1.DefaultCellStyle.BackColor = Color.FromArgb(193, 208, 222);

                    DGV1.BackgroundColor = Color.FromArgb(193, 208, 222);
                    DGV1.GridColor = Color.FromArgb(75, 94, 129);
                    DGV1.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(224, 224, 224);
                    DGV1.AlternatingRowsDefaultCellStyle.ForeColor = Color.FromArgb(0, 0, 0);        // black
                    DGV1.DefaultCellStyle.BackColor = Color.FromArgb(193, 208, 222);
                    break;
                case 2:
                    //
                    DGV1.BackgroundColor = Color.FromArgb(255, 255, 192);
                    DGV1.GridColor = Color.FromArgb(214, 10, 46);
                    DGV1.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 192);
                    break;
            }

            #endregion

            try
            {
                #region Prepare Column Strings and Arrays

                // Prepare Column Strings and Arrays 
                if (DGV1.RowCount == 0)
                {
                    //DGV1.RowCount = 1;
                }

                // Column Headers
                string[] ColHeaderArr = pColHeader.Split(',');
                //if (ColHeaderArr.Count() < pColTotal)
                //{
                //    pColTotal = ColHeaderArr.Count();
                //}

                // Grid headerWidth 
                if (pColWidth.Trim().Length == 0)
                {
                    pColWidth = StrRepeate("10", pColTotal);
                    if (pColWidth == "Err")
                    {
                        // Reaise Error
                    }
                }
                string[] ColWidthArr = pColWidth.Split(',');
                // Column Max Input Length
                string[] ColMaxInputLenArr;
                if (pColMaxInputLen.Trim().Length == 0)
                {
                    pColMaxInputLen = StrRepeate("0", pColTotal);
                    if (pColMaxInputLen == "Err")
                    {
                        // Reaise Error
                    }
                    ColMaxInputLenArr = pColMaxInputLen.Split(',');
                    //ColMaxInputLenArr = new string[] { "0" };
                    //string[] names = new string[3] { "Matt", "Joanne", "Robert" };
                }
                else
                {
                    ColMaxInputLenArr = pColMaxInputLen.Split(',');
                }
                // Column Format
                if (pColFormat.Trim().Length == 0)
                {
                    pColFormat = StrRepeate("T", pColTotal);
                    if (pColFormat == "Err")
                    {
                        // Reaise Error
                    }

                }
                string[] ColFormatArr = pColFormat.Split(',');
                // Column Width
                if (pColWidth.Trim().Length == 0)
                {
                    pColWidth = StrRepeate("10", pColTotal);
                    if (pColWidth == "Err")
                    {
                        // Reaise Error
                    }
                }
                // Column ReadOnly
                if (pColReadyOnly.Trim().Length == 0)
                {
                    // 1 = ReadOnly, 0 = Read/Write 
                    pColReadyOnly = StrRepeate("1", pColTotal);
                    if (pColWidth == "Err")
                    {
                        // Reaise Error
                    }
                }
                else
                {
                    if (pColReadyOnly.Trim() == "1")
                    {
                        // All Read Only
                        pColReadyOnly = StrRepeate("1", pColTotal);
                        if (pColWidth == "Err")
                        {
                            // Reaise Error
                        }

                    }
                    else if (pColReadyOnly.Trim() == "0")
                    {
                        // All Read/Write
                        pColReadyOnly = StrRepeate("0", pColTotal);
                        if (pColWidth == "Err")
                        {
                            // Reaise Error
                        }
                    }
                }
                string[] ColReadyOnlyArr = pColReadyOnly.Split(',');
                // Check Lengths are same as ColumnTotal
                if (ColHeaderArr.Count() != pColTotal ||
                    ColWidthArr.Count() != pColTotal ||
                    ColMaxInputLenArr.Count() != pColTotal ||
                    ColFormatArr.Count() != pColTotal ||
                    ColReadyOnlyArr.Count() != pColTotal)
                {
                    MessageBox.Show("Array Length Conflict. See Debug Info:>>> " + DGV1.Name.ToString(), "Grid Header");
                    return;
                }

                #endregion Prepare Column Strings and Arrays

                #region Column Create

                if (pGridType == "DATA")
                {
                    #region Data Grid
                    // Create Columns: Assign Column Properties
                    for (int i = 0; i < pColTotal; i++)
                    {
                        switch (ColFormatArr[i].Trim())
                        {
                            case "T":
                            case "H":
                            case "TI":
                                {
                                    // T = Text
                                    // H = Hidden
                                    // TI = Text Box Integer
                                    var col4 = new DataGridViewTextBoxColumn();
                                    col4.Name = "Column4" + i.ToString();
                                    if (Convert.ToInt32(ColMaxInputLenArr[i]) != 0)
                                    {
                                        col4.MaxInputLength = Convert.ToInt32(ColMaxInputLenArr[i]);
                                    }
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }
                            case "N2":
                                {
                                    // Numeric 2 digit
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 2;
                                    col4.Name = "Column4" + i.ToString();
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }

                            case "N3":
                                {
                                    // Numeric 3 digit
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 3;
                                    col4.Name = "Column4" + i.ToString();
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }

                            case "N4":
                                {
                                    var col4 = new TNumEditDataGridViewColumn();
                                    col4.DecimalLength = 4;
                                    col4.Name = "Column4" + i.ToString();
                                    if (ColReadyOnlyArr[i].Trim() == "1")
                                    {
                                        col4.ReadOnly = true;
                                    }
                                    DGV1.Columns.Add(col4);
                                    break;
                                }
                        } // End switch statement

                    } // end for create column
                    #endregion
                }
                else
                {
                    #region Lookup Grid

                    // Comented in old version: 2012 05 13 commented to implement TN
                    if (DGV1.ColumnCount < pColTotal)
                    {
                        DGV1.ColumnCount = pColTotal;
                    }

                    #endregion LOOKUP GRID
                }
                #endregion Create Columns

                #region Column Allignment

                // Column Allignment and 
                for (int i = 0; i < pColTotal; i++)
                {

                    DGV1.Columns[i].HeaderText = ColHeaderArr[i];
                    DGV1.Columns[i].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                    if (ColFormatArr[i].Trim() != "H")
                    {
                        DGV1.Columns[i].Width = widM * Convert.ToInt32(ColWidthArr[i]);
                    }
                    else
                    {
                        DGV1.Columns[i].Visible = false;
                    }
                    switch (ColFormatArr[i].Trim())
                    {
                        case "N2":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                DGV1.Columns[i].ValueType = typeof(decimal);
                                DGV1.Columns[i].DefaultCellStyle.Format = "N2";
                                break;
                            }
                        case "N3":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                DGV1.Columns[i].ValueType = typeof(decimal);
                                DGV1.Columns[i].DefaultCellStyle.Format = "N3";
                                break;
                            }
                        case "N4":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                DGV1.Columns[i].ValueType = typeof(decimal);
                                DGV1.Columns[i].DefaultCellStyle.Format = "N4";
                                break;
                            }
                        case "TI":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                                break;
                            }

                    }
                    switch (ColFormatArr[i].Trim())
                    {
                        case "C":
                            {
                                DGV1.Columns[i].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                                break;
                            }
                    } // end Switch statement

                } // End for loop

                #endregion Column Allignment
                if (ColHeaderArr.Length != ColWidthArr.Length)
                {
                    MessageBox.Show("Warnning: Number of Header Titles and Header Width paramenters are not equal ...", "Set Grid Header");
                }

            }
            catch (Exception exp)
            {
                MessageBox.Show("Exception: " + exp.Message, "Grid Header Setting");
            }
        }