예제 #1
0
        private void PopulateColumns()
        {
            BusyPopulatingColumns = true;
            EditColumns.Clear();
            dataGridViewX1.Columns.Clear();

            if (ShowDeleteColumn)
            {
                DataGridViewImageColumn col = new DataGridViewImageColumn();
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                col.DefaultCellStyle.NullValue = DeleteImage;
                col.HeaderText = "";
                col.Frozen = FrozenColumnIndex.HasValue;
                dataGridViewX1.Columns.Add(col);
            }
            for (int i = 0; i < Columns.Count; i++)
            {
                ColumnItem column = Columns[i];
                //DataGridViewColumn colNullableCheckbox = null;
                DataGridViewColumn col = null;

                switch (column.ControlType)
                {
                    case ColumnItem.ColumnTypes.Checkbox:
                        col = new DataGridViewCheckBoxColumn();
                        break;
                    case ColumnItem.ColumnTypes.Textbox:
                        col = new DataGridViewTextBoxColumnEx();
                        ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor;
                        ((DataGridViewTextBoxColumnEx)col).InvalidColor = InvalidColor;
                        ((DataGridViewTextBoxColumnEx)col).BackColor = BackColor;
                        break;
                    case ColumnItem.ColumnTypes.IntegerInput:
                        col = new DataGridViewIntegerInputColumn();
                        ((DataGridViewIntegerInputColumn)col).DisplayControlForCurrentCellOnly = true;
                        ((DataGridViewIntegerInputColumn)col).BackgroundStyle.Border = eStyleBorderType.None;
                        ((DataGridViewIntegerInputColumn)col).ShowUpDown = true;
                        break;
                    case ColumnItem.ColumnTypes.NullableCheckBox:
                        col = new DataGridViewComboBoxColumnEx();
                        List<string> vals = new List<string>(new string[] { "", "True", "False" });
                        ((DataGridViewComboBoxColumnEx)col).DataSource = vals;
                        ((DataGridViewComboBoxColumnEx)col).DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                        ((DataGridViewComboBoxColumnEx)col).FlatStyle = FlatStyle.Flat;
                        ((DataGridViewComboBoxColumnEx)col).DisabledColor = DisabledColor;
                        ((DataGridViewComboBoxColumnEx)col).InvalidColor = InvalidColor;
                        ((DataGridViewComboBoxColumnEx)col).BackColor = BackColor;
                        break;
                    case ColumnItem.ColumnTypes.NullableTextBox:
                        col = new DataGridViewTextBoxColumnEx();
                        ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor;
                        ((DataGridViewTextBoxColumnEx)col).InvalidColor = InvalidColor;
                        ((DataGridViewTextBoxColumnEx)col).BackColor = BackColor;
                        break;
                    case ColumnItem.ColumnTypes.NullableIntegerInput:
                        col = new DataGridViewTextBoxColumnEx();
                        ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor;
                        ((DataGridViewTextBoxColumnEx)col).InvalidColor = InvalidColor;
                        ((DataGridViewTextBoxColumnEx)col).BackColor = BackColor;
                        ((DataGridViewTextBoxColumnEx)col).Alignment = DataGridViewContentAlignment.MiddleRight;
                        break;
                    case ColumnItem.ColumnTypes.ComboBox:
                        col = new DataGridViewComboBoxColumnEx();
                        List<string> keys = column.ComboItems.Keys.ToList();
                        keys.Sort();
                        ((DataGridViewComboBoxColumnEx)col).DataSource = keys;
                        ((DataGridViewComboBoxColumnEx)col).DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
                        ((DataGridViewComboBoxColumnEx)col).FlatStyle = FlatStyle.Flat;
                        ((DataGridViewComboBoxColumnEx)col).DisabledColor = DisabledColor;
                        ((DataGridViewComboBoxColumnEx)col).InvalidColor = InvalidColor;
                        ((DataGridViewComboBoxColumnEx)col).BackColor = BackColor;
                        break;
                    case ColumnItem.ColumnTypes.Image:
                        col = new DataGridViewImageColumn();
                        break;
                    case ColumnItem.ColumnTypes.Link:
                        col = new DataGridViewLinkColumn();
                        break;
                    case ColumnItem.ColumnTypes.None:
                        col = new DataGridViewLinkColumn();
                        break;
                    default:
                        throw new NotImplementedException("Not handled yet");
                }
                //if (colNullableCheckbox != null)
                //{
                //    colNullableCheckbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;// true;
                //    colNullableCheckbox.Resizable = DataGridViewTriState.False;// false;
                //    dataGridViewX1.Columns.Add(colNullableCheckbox);
                //}
                col.Frozen = (FrozenColumnIndex.HasValue && i < FrozenColumnIndex);
                col.HeaderText = column.Text;
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;//.AllCells;
                col.Resizable = DataGridViewTriState.True;
                col.ReadOnly = column.ReadOnly;
                dataGridViewX1.Columns.Add(col);
                EditColumns.Add(dataGridViewX1.Columns.Count - 1, i);
            }
            //dataGridViewX1.Columns[1].Frozen = true;
            BusyPopulatingColumns = false;
        }
예제 #2
0
        private void PopulateColumns()
        {
            BusyPopulatingColumns = true;
            EditColumns.Clear();
            dataGridViewX1.Columns.Clear();

            if (ShowDeleteColumn)
            {
                DataGridViewImageColumn col = new DataGridViewImageColumn();
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                col.DefaultCellStyle.NullValue = DeleteImage;
                col.HeaderText = "";
                col.Frozen     = FrozenColumnIndex.HasValue;
                dataGridViewX1.Columns.Add(col);
            }
            for (int i = 0; i < Columns.Count; i++)
            {
                ColumnItem column = Columns[i];
                //DataGridViewColumn colNullableCheckbox = null;
                DataGridViewColumn col = null;

                switch (column.ControlType)
                {
                case ColumnItem.ColumnTypes.Checkbox:
                    col = new DataGridViewCheckBoxColumn();
                    break;

                case ColumnItem.ColumnTypes.Textbox:
                    col = new DataGridViewTextBoxColumnEx();
                    ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor;
                    ((DataGridViewTextBoxColumnEx)col).InvalidColor  = InvalidColor;
                    ((DataGridViewTextBoxColumnEx)col).BackColor     = BackColor;
                    break;

                case ColumnItem.ColumnTypes.IntegerInput:
                    col = new DataGridViewIntegerInputColumn();
                    ((DataGridViewIntegerInputColumn)col).DisplayControlForCurrentCellOnly = true;
                    ((DataGridViewIntegerInputColumn)col).BackgroundStyle.Border           = eStyleBorderType.None;
                    ((DataGridViewIntegerInputColumn)col).ShowUpDown = true;
                    break;

                case ColumnItem.ColumnTypes.NullableCheckBox:
                    col = new DataGridViewComboBoxColumnEx();
                    List <string> vals = new List <string>(new string[] { "", "True", "False" });
                    ((DataGridViewComboBoxColumnEx)col).DataSource    = vals;
                    ((DataGridViewComboBoxColumnEx)col).DisplayStyle  = DataGridViewComboBoxDisplayStyle.ComboBox;
                    ((DataGridViewComboBoxColumnEx)col).FlatStyle     = FlatStyle.Flat;
                    ((DataGridViewComboBoxColumnEx)col).DisabledColor = DisabledColor;
                    ((DataGridViewComboBoxColumnEx)col).InvalidColor  = InvalidColor;
                    ((DataGridViewComboBoxColumnEx)col).BackColor     = BackColor;
                    break;

                case ColumnItem.ColumnTypes.NullableTextBox:
                    col = new DataGridViewTextBoxColumnEx();
                    ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor;
                    ((DataGridViewTextBoxColumnEx)col).InvalidColor  = InvalidColor;
                    ((DataGridViewTextBoxColumnEx)col).BackColor     = BackColor;
                    break;

                case ColumnItem.ColumnTypes.NullableIntegerInput:
                    col = new DataGridViewTextBoxColumnEx();
                    ((DataGridViewTextBoxColumnEx)col).DisabledColor = DisabledColor;
                    ((DataGridViewTextBoxColumnEx)col).InvalidColor  = InvalidColor;
                    ((DataGridViewTextBoxColumnEx)col).BackColor     = BackColor;
                    ((DataGridViewTextBoxColumnEx)col).Alignment     = DataGridViewContentAlignment.MiddleRight;
                    break;

                case ColumnItem.ColumnTypes.ComboBox:
                    col = new DataGridViewComboBoxColumnEx();
                    List <string> keys = column.ComboItems.Keys.ToList();
                    keys.Sort();
                    ((DataGridViewComboBoxColumnEx)col).DataSource    = keys;
                    ((DataGridViewComboBoxColumnEx)col).DisplayStyle  = DataGridViewComboBoxDisplayStyle.ComboBox;
                    ((DataGridViewComboBoxColumnEx)col).FlatStyle     = FlatStyle.Flat;
                    ((DataGridViewComboBoxColumnEx)col).DisabledColor = DisabledColor;
                    ((DataGridViewComboBoxColumnEx)col).InvalidColor  = InvalidColor;
                    ((DataGridViewComboBoxColumnEx)col).BackColor     = BackColor;
                    break;

                case ColumnItem.ColumnTypes.Image:
                    col = new DataGridViewImageColumn();
                    break;

                case ColumnItem.ColumnTypes.Link:
                    col = new DataGridViewLinkColumn();
                    break;

                case ColumnItem.ColumnTypes.None:
                    col = new DataGridViewLinkColumn();
                    break;

                default:
                    throw new NotImplementedException("Not handled yet");
                }
                //if (colNullableCheckbox != null)
                //{
                //    colNullableCheckbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;// true;
                //    colNullableCheckbox.Resizable = DataGridViewTriState.False;// false;
                //    dataGridViewX1.Columns.Add(colNullableCheckbox);
                //}
                col.Frozen       = (FrozenColumnIndex.HasValue && i < FrozenColumnIndex);
                col.HeaderText   = column.Text;
                col.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;                //.AllCells;
                col.Resizable    = DataGridViewTriState.True;
                col.ReadOnly     = column.ReadOnly;
                dataGridViewX1.Columns.Add(col);
                EditColumns.Add(dataGridViewX1.Columns.Count - 1, i);
            }
            //dataGridViewX1.Columns[1].Frozen = true;
            BusyPopulatingColumns = false;
        }