コード例 #1
0
        private void queryBuilder1_QueryElementControlCreated(QueryElement queryElement, IQueryElementControl queryElementControl)
        {
            if (queryElementControl is IQueryColumnListControl)
            {
                IQueryColumnListControl queryColumnListControl = (IQueryColumnListControl)queryElementControl;
                DataGridView            dataGridView           = (DataGridView)queryColumnListControl.DataGrid;

                _customColumn?.Dispose();

                // Create custom column
                _customColumn = new DataGridViewComboBoxColumn
                {
                    Name         = "CustomColumn",
                    HeaderText   = "Custom Column",
                    Width        = 200,
                    DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing, // hide the combobox if cell is not focused
                    ValueType    = typeof(string)
                };

                _customColumn.HeaderCell.Style.Font = new Font("Tahoma", 8, FontStyle.Bold);

                // Insert custom column to specified position
                dataGridView.Columns.Insert(2, _customColumn);

                // Handle the necessary events
                dataGridView.CellEnter             += DataGridView_CellEnter;
                dataGridView.CellLeave             += DataGridView_CellLeave;
                dataGridView.CellBeginEdit         += DataGridView_CellBeginEdit;
                dataGridView.CellValueNeeded       += DataGridView_CellValueNeeded;
                dataGridView.CellValuePushed       += DataGridView_CellValuePushed;
                dataGridView.EditingControlShowing += DataGridView_EditingControlShowing;
            }
        }
コード例 #2
0
        /// <summary>
        /// 列追加(コンボボックス)
        /// </summary>
        /// <param name="dgv">DataGridViewオブジェクト</param>
        /// <param name="HeaderText"></param>
        /// <param name="DataPropertyName"></param>
        /// <param name="DataSrcTbl">コンボボックス用テーブル(表示タイトルと元データタイトルで構成)</param>
        /// <param name="ValueMember">元データタイトル</param>
        /// <param name="DisplayMember">表示タイトル</param>
        static public void AddCol_ComboBox(DataGridView dgv, string HeaderText, string ColName, string DataPropertyName,
                                           object DataSrcTbl, string ValueMember, string DisplayMember)
        {
            DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();

            col.DataPropertyName = DataPropertyName;
            col.HeaderText       = HeaderText;
            col.Name             = ColName;
            col.DataSource       = DataSrcTbl;
            col.ValueMember      = ValueMember;
            col.DisplayMember    = DisplayMember;
            col.SortMode         = DataGridViewColumnSortMode.NotSortable;
            dgv.Columns.Add(col);
            col.Dispose();
        }