Exemple #1
0
        /// <summary>
        /// 创建DataGridView的ComboBox列
        /// </summary>
        /// <param name="_dgv">要创建列的DataGridView</param>
        /// <param name="_alignment">设置列的对齐方式</param>
        /// <param name="_columnName">列名</param>
        /// <param name="_headerText">标题名</param>
        /// <param name="_dataPropertyName">绑定数据源的字段名称</param>
        /// <param name="_toolTipText">TipText提示</param>
        /// <param name="_readOnly">设置列是否只读,true 只读,false 读写</param>
        /// <param name="_visible">设置列是否可见,true 显示,false 隐藏</param>
        /// <param name="_cboDataSource">绑定ComboBox的数据源</param>
        /// <param name="_displayMember">用于显示的字段名</param>
        /// <param name="_valueMember">绑定Value的字段名</param>
        /// <param name="_maxDropDownItems">设置显示最大的下拉项条数</param>
        /// <param name="_cboDisplayStyle">设置显示类型</param>
        /// <param name="_notEmpty">设置列是否为必填列,true 必填,false 非必填</param>
        /// <param name="_backColor">设置列的背景色,当_notEmpty为true时,此项为必需值,为false,此项可以为Color.Empty</param>
        /// <param name="_columnState">装载DataGridView可写可读、只读列的数据字典</param>
        public static void InitDgvComboBoxColumn(DataGridView _dgv,
                                                 DataGridViewContentAlignment _alignment, string _columnName, string _headerText,
                                                 string _dataPropertyName, string _toolTipText, bool _readOnly, bool _visible,
                                                 DataTable _cboDataSource, string _displayMember, string _valueMember,
                                                 int _maxDropDownItems, DataGridViewComboBoxDisplayStyle _cboDisplayStyle,
                                                 bool _notEmpty, Color _backColor, ref Dictionary <string, bool> _columnState)
        {
            DataGridViewComboBoxColumn comboBoxCol = new DataGridViewComboBoxColumn();

            comboBoxCol.HeaderCell.Style.Alignment = _alignment == 0 ? DataGridViewContentAlignment.MiddleLeft : _alignment;
            comboBoxCol.Name             = _columnName;
            comboBoxCol.HeaderText       = _headerText;
            comboBoxCol.DataPropertyName = _dataPropertyName;
            comboBoxCol.ToolTipText      = _toolTipText;
            comboBoxCol.Visible          = _visible;
            comboBoxCol.ReadOnly         = _readOnly;
            comboBoxCol.DataSource       = _cboDataSource;
            comboBoxCol.DisplayMember    = _displayMember;
            comboBoxCol.ValueMember      = _valueMember;
            comboBoxCol.MaxDropDownItems = _maxDropDownItems;
            comboBoxCol.DisplayStyle     = _cboDisplayStyle;
            comboBoxCol.AutoComplete     = _cboDisplayStyle == DataGridViewComboBoxDisplayStyle.ComboBox ? true : false;
            if (_notEmpty == true)
            {
                comboBoxCol.DefaultCellStyle.BackColor = _backColor;
            }
            _columnState.Add(_columnName, _readOnly);
            _dgv.Columns.Add(comboBoxCol);
        }
		public DataGridViewComboBoxColumn ()
		{
			CellTemplate = new DataGridViewComboBoxCell();
			((DataGridViewComboBoxCell) CellTemplate).OwningColumnTemplate = this;
			SortMode = DataGridViewColumnSortMode.NotSortable;
			autoComplete = true;
			displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
			displayStyleForCurrentCellOnly = false;
		}
Exemple #3
0
 public DataGridViewComboBoxColumn()
 {
     CellTemplate = new DataGridViewComboBoxCell();
     ((DataGridViewComboBoxCell)CellTemplate).OwningColumnTemplate = this;
     SortMode     = DataGridViewColumnSortMode.NotSortable;
     autoComplete = true;
     displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
     displayStyleForCurrentCellOnly = false;
 }
        //=====================================================================
        /// <summary>
        /// Constructor
        /// </summary>
        protected BaseComboBoxCell()
        {
            maxDropDownItems = 8;
            displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
            flatStyle = FlatStyle.Standard;
            displayMember = valueMember = String.Empty;

            miParseFormattedValueInternal = base.GetType().GetMethod("ParseFormattedValueInternal",
                BindingFlags.NonPublic | BindingFlags.Instance);
        }
		public DataGridViewComboBoxCell () : base() {
			autoComplete = true;
			dataSource = null;
			displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
			displayStyleForCurrentCellOnly = false;
			dropDownWidth = 1;
			flatStyle = FlatStyle.Standard;
			items = new ObjectCollection(this);
			maxDropDownItems = 8;
			sorted = false;
			owningColumnTemlate = null;
		}
 public DataGridViewComboBoxCell() : base()
 {
     autoComplete = true;
     dataSource   = null;
     displayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
     displayStyleForCurrentCellOnly = false;
     dropDownWidth       = 1;
     flatStyle           = FlatStyle.Standard;
     items               = new ObjectCollection(this);
     maxDropDownItems    = 8;
     sorted              = false;
     owningColumnTemlate = null;
 }
Exemple #7
0
        public static void SetColumnComboBox(this DataGridView gv, int colIndex, object dataSource, DataGridViewComboBoxDisplayStyle dispStyle = DataGridViewComboBoxDisplayStyle.DropDownButton)
        {
            DataGridViewComboBoxColumn col = gv.Columns[colIndex] as DataGridViewComboBoxColumn;

            col.ValueMember   = "VALUE";
            col.DisplayMember = "DISPLAY";
            col.DataSource    = dataSource;
            col.Width         = 200;
            col.DisplayStyle  = dispStyle;
        }
        public void DataGridViewComboBoxCellAccessibleObject_ControlType_ReturnExpected(DataGridViewComboBoxDisplayStyle displayStyle, bool cellIsEdited, int expectedControlType)
        {
            using var dataGridView = new DataGridView();
            dataGridView.Columns.Add(new DataGridViewComboBoxColumn()
            {
                DisplayStyle = displayStyle
            });
            dataGridView.Rows.Add();
            dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0];

            if (cellIsEdited)
            {
                dataGridView.BeginEdit(false);
            }

            int actualPropertyValue = (int)dataGridView.Rows[0].Cells[0].AccessibilityObject.GetPropertyValue(UiaCore.UIA.ControlTypePropertyId);

            Assert.Equal(expectedControlType, actualPropertyValue);
        }
        public void DataGridViewComboBoxCellAccessibleObject_SupportExpandCollapsePattern_ReturnExpected(DataGridViewComboBoxDisplayStyle displayStyle, bool cellIsEdited, bool expectedValue)
        {
            using var dataGridView = new DataGridView();
            dataGridView.Columns.Add(new DataGridViewComboBoxColumn()
            {
                DisplayStyle = displayStyle
            });
            dataGridView.Rows.Add();
            dataGridView.CurrentCell = dataGridView.Rows[0].Cells[0];

            if (cellIsEdited)
            {
                dataGridView.BeginEdit(false);
            }

            object actualPropertyValue = dataGridView.Rows[0].Cells[0].AccessibilityObject.GetPropertyValue(UiaCore.UIA.IsExpandCollapsePatternAvailablePropertyId);

            Assert.Equal(expectedValue, actualPropertyValue);
        }