Example #1
0
        public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle)
        {
            base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
            Controls.ComboBoxExtended control = DataGridView.EditingControl as Controls.ComboBoxExtended;
            NjitComboBoxColumn        column  = (this.OwningColumn as NjitComboBoxColumn);

            foreach (var property in column.ComboBoxExtended.GetType().GetProperties())
            {
                var attributes = property.GetCustomAttributes(typeof(System.ComponentModel.CategoryAttribute), true);
                if (attributes.Length == 1 && ((System.ComponentModel.CategoryAttribute)attributes[0]).Category == "Njit" && property.CanRead && property.CanWrite)
                {
                    property.SetValue(control, property.GetValue(column.ComboBoxExtended, null), null);
                }
            }
            if (control.EditItemsEnabled == false)
            {
                if (control.DataSource == null)
                {
                    control.Items.Clear();
                    foreach (object item in column.ComboBoxExtended.Items)
                    {
                        control.Items.Add(item);
                    }
                }
            }
            else
            {
                control.RefreshData();
            }
            control.DropDownStyle            = column.ComboBoxExtended.DropDownStyle;
            control.AutoCompleteMode         = column.ComboBoxExtended.AutoCompleteMode;
            control.AutoCompleteSource       = column.ComboBoxExtended.AutoCompleteSource;
            control.AutoCompleteCustomSource = column.ComboBoxExtended.AutoCompleteCustomSource;

            control.DataSource    = column.ComboBoxExtended.DataSource;
            control.DisplayMember = column.ComboBoxExtended.DisplayMember;
            control.ValueMember   = column.ComboBoxExtended.ValueMember;
            if (control.DataSource != null && control.Items.Count > 0 && this.SelectedValue != null)
            {
                control.SelectedValue = this.SelectedValue;
                this.RaiseCellValueChanged(new System.Windows.Forms.DataGridViewCellEventArgs(this.ColumnIndex, this.RowIndex));
            }
            else
            {
                if (this.Value == null || this.Value == DBNull.Value)
                {
                    if ((this.OwningColumn as NjitComboBoxColumn).DefaultValue.IsNullOrEmpty() == false)
                    {
                        control.Text = (this.OwningColumn as NjitComboBoxColumn).DefaultValue;
                    }
                }
                else
                {
                    control.Text = this.Value.ToString();
                }
            }
            DataGridView.CellValidating  += DataGridViewCellValidating;
            control.SelectedValueChanged += control_SelectedValueChanged;
        }
Example #2
0
        public override object Clone()
        {
            NjitComboBoxColumn copy = base.Clone() as NjitComboBoxColumn;

            foreach (var property in copy.GetType().GetProperties())
            {
                var attributes = property.GetCustomAttributes(typeof(System.ComponentModel.CategoryAttribute), true);
                if (attributes.Length == 1 && ((System.ComponentModel.CategoryAttribute)attributes[0]).Category == "Njit" && property.CanRead && property.CanWrite)
                {
                    property.SetValue(copy, property.GetValue(this, null), null);
                }
            }
            return(copy);
        }