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 DataGridViewCheckBoxColumn { Name = "CustomColumn", HeaderText = "Custom Column", Width = 100, FlatStyle = FlatStyle.Standard, ValueType = typeof(CheckState), TrueValue = CheckState.Checked, FalseValue = CheckState.Unchecked, IndeterminateValue = CheckState.Indeterminate }; _customColumn.HeaderCell.Style.Font = new Font("Tahoma", 8, FontStyle.Bold); // Insert custom column to specified position dataGridView.Columns.Insert(2, _customColumn); // Handle required events dataGridView.CellBeginEdit += DataGridView_CellBeginEdit; dataGridView.CellValueNeeded += DataGridView_CellValueNeeded; dataGridView.CellValuePushed += DataGridView_CellValuePushed; } }
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 ComboBoxWithButtonColumn { 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); _customColumn.ShowButton = true; // Insert custom column to specified position dataGridView.Columns.Insert(2, _customColumn); // Handle requierd 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; } }
private void queryBuilder1_QueryElementControlDestroying(QueryElement queryElement, IQueryElementControl queryElementControl) { if (queryElementControl is IQueryColumnListControl) { IQueryColumnListControl queryColumnListControl = (IQueryColumnListControl)queryElementControl; DataGridView dataGridView = (DataGridView)queryColumnListControl.DataGrid; // remove event handlers to avoid memory leaking dataGridView.CellBeginEdit -= DataGridView_CellBeginEdit; dataGridView.CellValueNeeded -= DataGridView_CellValueNeeded; dataGridView.CellValuePushed -= DataGridView_CellValuePushed; } }