internal void SyncItems() { if (DataSource != null || OwningColumnTemplate == null) { return; } if (OwningColumnTemplate.DataGridView != null) { DataGridViewComboBoxEditingControl editor = OwningColumnTemplate.DataGridView.EditingControl as DataGridViewComboBoxEditingControl; if (editor != null) { object selectedItem = editor.SelectedItem; editor.Items.Clear(); editor.Items.AddRange(items); if (editor.Items.IndexOf(selectedItem) != -1) { editor.SelectedItem = selectedItem; } } } // Push the new items to the column OwningColumnTemplate.SyncItems(Items); }
private void dgvLineaCompra_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { dgvCombo = e.Control as DataGridViewComboBoxEditingControl; if (dgvCombo != null) { dgvCombo.SelectedIndexChanged += new EventHandler(dgvLineaCompra_SelectedIndexChanged); } }
public static void BindComboBoxCellDataSource(DataGridViewComboBoxEditingControl control, string[][] dataSource) { if (dataSource == null || dataSource.Length.Equals(0)) return; List<DataSourceNode> dataSourceNodeList = BindArrayDataHelper.GetDataSource(dataSource, 0, 1); control.DataSource = dataSourceNodeList; control.DisplayMember = "Text"; control.ValueMember = "Value"; }
protected override void OnMouseDown(DataGridViewCellMouseEventArgs e) { base.OnMouseDown(e); if (!ReadOnly) { // Any mouse-click on the cell should be passed along to any // combo-box control. if (IsInEditMode) { DataGridViewComboBoxEditingControl cb = (DataGridView.EditingControl as DataGridViewComboBoxEditingControl); if (cb != null) { cb.OnMouseDownInternal(e); } } } }
public DataGridViewComboBoxEditingControlAccessibleObject(DataGridViewComboBoxEditingControl ownerControl) : base(ownerControl) { this.ownerControl = ownerControl; }
/// <summary> /// Event when UserContorl to edit cell is shown. /// </summary> /// <param name="sender">DataGridView.</param> /// <param name="e">DataGridViewEditingControlShowingEventArgs</param> private void m_dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { DataGridViewCell cell = m_dgv[1, m_dgv.CurrentCell.RowIndex]; if (cell.Tag is string) { if ((string)cell.Tag == "ClassName" && cell is DataGridViewComboBoxCell) { m_combo = (DataGridViewComboBoxEditingControl)e.Control; m_combo.SelectedIndexChanged += new EventHandler(combo_selectedIndexChanged); } } }
/// <summary> /// End to edit the current cell. /// </summary> /// <param name="sender">DataGridViewCell.</param> /// <param name="e">DataGridViewCellEventArgs</param> void m_dgv_CellEndEdit(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { if (m_combo != null) { m_combo.SelectedIndexChanged -= new System.EventHandler(combo_selectedIndexChanged); m_combo = null; } }
public void TestBindingToDataGridViewComboBoxEditingControl() { DataGridViewComboBoxEditingControl control = new DataGridViewComboBoxEditingControl(); IBusinessObject obj = new BusinessObject(); using(BindingScope scope = new BindingScope()) { IBusinessObject bindableSource = scope.CreateSource(obj); if(control is Control) ((Control)control).CreateControl(); control.BindingContext = new BindingContext(); DataGridViewComboBoxEditingControl bindableTarget = scope.CreateTarget(control); int dataBindingsBeforeEditingControlRowIndex = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.EditingControlRowIndex); Assert.AreEqual(dataBindingsBeforeEditingControlRowIndex + 1, control.DataBindings.Count); Assert.AreEqual(control.EditingControlRowIndex, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.EditingControlRowIndex, obj.IntValue); int dataBindingsBeforeDropDownWidth = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.DropDownWidth); Assert.AreEqual(dataBindingsBeforeDropDownWidth + 1, control.DataBindings.Count); Assert.AreEqual(control.DropDownWidth, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.DropDownWidth, obj.IntValue); int dataBindingsBeforeDropDownHeight = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.DropDownHeight); Assert.AreEqual(dataBindingsBeforeDropDownHeight + 1, control.DataBindings.Count); Assert.AreEqual(control.DropDownHeight, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.DropDownHeight, obj.IntValue); int dataBindingsBeforeMaxDropDownItems = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.MaxDropDownItems); Assert.AreEqual(dataBindingsBeforeMaxDropDownItems + 1, control.DataBindings.Count); Assert.AreEqual(control.MaxDropDownItems, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.MaxDropDownItems, obj.IntValue); int dataBindingsBeforeMaxLength = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.MaxLength); Assert.AreEqual(dataBindingsBeforeMaxLength + 1, control.DataBindings.Count); Assert.AreEqual(control.MaxLength, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.MaxLength, obj.IntValue); int dataBindingsBeforeText = control.DataBindings.Count; scope.Bind(bindableSource.Name).To(bindableTarget.Text); Assert.AreEqual(dataBindingsBeforeText + 1, control.DataBindings.Count); Assert.AreEqual(control.Text, obj.Name); obj.ChangeName(); Assert.AreEqual(control.Text, obj.Name); int dataBindingsBeforeDisplayMember = control.DataBindings.Count; scope.Bind(bindableSource.Name).To(bindableTarget.DisplayMember); Assert.AreEqual(dataBindingsBeforeDisplayMember + 1, control.DataBindings.Count); Assert.AreEqual(control.DisplayMember, obj.Name); obj.ChangeName(); Assert.AreEqual(control.DisplayMember, obj.Name); int dataBindingsBeforeFormatString = control.DataBindings.Count; scope.Bind(bindableSource.Name).To(bindableTarget.FormatString); Assert.AreEqual(dataBindingsBeforeFormatString + 1, control.DataBindings.Count); Assert.AreEqual(control.FormatString, obj.Name); obj.ChangeName(); Assert.AreEqual(control.FormatString, obj.Name); int dataBindingsBeforeValueMember = control.DataBindings.Count; scope.Bind(bindableSource.Name).To(bindableTarget.ValueMember); Assert.AreEqual(dataBindingsBeforeValueMember + 1, control.DataBindings.Count); Assert.AreEqual(control.ValueMember, obj.Name); obj.ChangeName(); Assert.AreEqual(control.ValueMember, obj.Name); int dataBindingsBeforeLeft = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.Left); Assert.AreEqual(dataBindingsBeforeLeft + 1, control.DataBindings.Count); Assert.AreEqual(control.Left, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.Left, obj.IntValue); int dataBindingsBeforeName = control.DataBindings.Count; scope.Bind(bindableSource.Name).To(bindableTarget.Name); Assert.AreEqual(dataBindingsBeforeName + 1, control.DataBindings.Count); Assert.AreEqual(control.Name, obj.Name); obj.ChangeName(); Assert.AreEqual(control.Name, obj.Name); int dataBindingsBeforeTabIndex = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.TabIndex); Assert.AreEqual(dataBindingsBeforeTabIndex + 1, control.DataBindings.Count); Assert.AreEqual(control.TabIndex, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.TabIndex, obj.IntValue); int dataBindingsBeforeTop = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.Top); Assert.AreEqual(dataBindingsBeforeTop + 1, control.DataBindings.Count); Assert.AreEqual(control.Top, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.Top, obj.IntValue); int dataBindingsBeforeWidth = control.DataBindings.Count; scope.Bind(bindableSource.IntValue).To(bindableTarget.Width); Assert.AreEqual(dataBindingsBeforeWidth + 1, control.DataBindings.Count); Assert.AreEqual(control.Width, obj.IntValue); obj.ChangeIntValue(); Assert.AreEqual(control.Width, obj.IntValue); } }
/************************************************************* * データグリッドビューの編集中のイベント追加 *************************************************************/ private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { DataGridView dgv = (DataGridView)sender; // コンボックスのイベント追加 if (e.Control is DataGridViewComboBoxEditingControl) { if (dgv.CurrentCell.OwningColumn.Name == "dgvMaterialCostName" || dgv.CurrentCell.OwningColumn.Name == "dgvPackingName" || dgv.CurrentCell.OwningColumn.Name == "dgvMachineName" || dgv.CurrentCell.OwningColumn.Name == "dgvPackingFareName") { dgvComboBox = (DataGridViewComboBoxEditingControl)e.Control; dgvComboBox.SelectedIndexChanged += new EventHandler(dgvComboBox_SelectedIndexChanged); dgvComboBox.Leave += new EventHandler(control_Leave_calc); } } // テキストボックスのイベント追加 if (e.Control is DataGridViewTextBoxEditingControl) { dgvTextBox = (DataGridViewTextBoxEditingControl)e.Control; dgvTextBox.Leave += new EventHandler(control_Leave_calc); if (dgv.CurrentCell.OwningColumn.Name == "dgvMaterialCostQuantity" || dgv.CurrentCell.OwningColumn.Name == "dgvContractorsQuantity" || dgv.CurrentCell.OwningColumn.Name == "dgvContractorsCost" || dgv.CurrentCell.OwningColumn.Name == "dgvMaterialsFareQuantity" || dgv.CurrentCell.OwningColumn.Name == "dgvMaterialsFareCost" || dgv.CurrentCell.OwningColumn.Name == "dgvPackingQuantity" || dgv.CurrentCell.OwningColumn.Name == "dgvMachineTime" || dgv.CurrentCell.OwningColumn.Name == "dgvPackingFareQuantity") { dgvTextBox.KeyPress += new KeyPressEventHandler(Event.textBox_KeyPress_numeric); } } }
/************************************************************* * データグリッドビューの編集後のイベント削除 *************************************************************/ private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { // コンボックスのイベント削除 if (dgvComboBox != null) { dgvComboBox.SelectedIndexChanged -= new EventHandler(dgvComboBox_SelectedIndexChanged); dgvComboBox.Leave -= new EventHandler(control_Leave_calc); dgvComboBox = null; } // テキストボックスのイベント削除 if (dgvTextBox != null) { dgvTextBox.KeyPress -= new KeyPressEventHandler(Event.textBox_KeyPress_numeric); dgvTextBox.Leave -= new EventHandler(control_Leave_calc); dgvTextBox = null; } calcAll(); }
private void dgwHousePropertys_EditingControlShowing(object sender, System.Windows.Forms.DataGridViewEditingControlShowingEventArgs e) { if (e.Control is System.Windows.Forms.DataGridViewComboBoxEditingControl) { System.Windows.Forms.DataGridViewComboBoxEditingControl control = (System.Windows.Forms.DataGridViewComboBoxEditingControl) e.Control; System.Collections.Generic.List<FasetItem> list = new System.Collections.Generic.List<FasetItem> { FasetItem.Null }; list.AddRange(Mappers.FasetItemMapper.FindByFasetId((short) this.dgwHousePropertys.CurrentRow.Cells.get_Item("fasetId").get_Value())); control.set_DataSource(list); if (control != this.dgwcbSave) { control.add_DropDownClosed(new System.EventHandler(this.dgwcb_DropDownClosed)); this.dgwcbSave = control; } } }
public void FillBoolColumnValue(DataGridViewComboBoxEditingControl ctrl) { ctrl.Items.Clear(); ctrl.Items.AddRange(new object[] {"True", "False"}); ctrl.SelectedIndex = 0; }
//结束编辑 private void dgvPaymentDetail_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (cboPaymentAccount != null) { cboPaymentAccount.SelectedValueChanged -= new EventHandler(cboPaymentAccount_SelectedValueChanged); cboPaymentAccount = null; } if (cboBalanceWay != null) { cboBalanceWay = null; } }
//添加明细 private void dgvPaymentDetail_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (dgvPaymentDetail.CurrentCell.OwningColumn == colPaymentAccount) { cboPaymentAccount = (DataGridViewComboBoxEditingControl)e.Control; cboPaymentAccount.SelectedIndexChanged += new EventHandler(cboPaymentAccount_SelectedValueChanged); } else if (dgvPaymentDetail.CurrentCell.OwningColumn == colBalanceWay) { cboBalanceWay = (DataGridViewComboBoxEditingControl)e.Control; cboBalanceWay.SelectedIndexChanged += new EventHandler(cboBalanceWay_SelectedValueChanged); } }
void clsWritableGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { try { Type t = e.Control.GetType(); comboedit = (DataGridViewComboBoxEditingControl)e.Control; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void FillBoolColumnValue(DataGridViewComboBoxEditingControl ctrl) { try { ctrl.Items.Clear(); ctrl.Items.AddRange(new object[] { "True" , "False" }); ctrl.SelectedIndex = 0; } catch (Exception oEx) { // LoggingHelper.ShowMessage(oEx); } }