//for event: caculate total price protected override void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (e.Control.GetType().Equals(typeof(DataGridViewTextBoxEditingControl)))//cell为类TextBox时 { e.CellStyle.BackColor = Color.FromName("window"); DataGridViewTextBoxEditingControl editingControl = e.Control as DataGridViewTextBoxEditingControl; editingControl.TextChanged -= new EventHandler(editingControl_TextChanged); editingControl.TextChanged += new EventHandler(editingControl_TextChanged); } else if (e.Control.GetType().Equals(typeof(DataGridViewComboBoxEditEditingControl)))//cell为price时 { e.CellStyle.BackColor = Color.FromName("window"); DataGridViewComboBoxEditEditingControl editingControl = e.Control as DataGridViewComboBoxEditEditingControl; editingControl.Items.Clear(); int productID = 0, customerID = 0; DataGridViewLookupCell cell = editingControl.EditingControlDataGridView.Rows[editingControl.EditingControlRowIndex].Cells["product"] as DataGridViewLookupCell; if (cell.Value != null && !string.IsNullOrEmpty((cell.Value as LookupArg).ArgName)) { productID = (int)(cell.Value as LookupArg).Value; } if (this.lookupText1.LookupArg != null) { int.TryParse(this.lookupText1.LookupArg.Value.ToString(), out customerID); } if (productID != 0 && customerID != 0) { List <string> prices = ProductStainlessCirculationRecordDao.getInstance().FindPriceList((int)conf.type, productID, customerID); //items是放在column里 editingControl.Items.AddRange(prices.ToArray()); } editingControl.TextChanged -= new EventHandler(editingControl_TextChanged); editingControl.TextChanged += new EventHandler(editingControl_TextChanged); } else if (e.Control.GetType().Equals(typeof(DataGridViewLookupEditingControl))) { DataGridViewLookupEditingControl editingControl = e.Control as DataGridViewLookupEditingControl; string columnName = this.dataGridView1.CurrentCell.OwningColumn.Name; editingControl.valueSetted -= new LookupText.ValueSetted(productEditingControl_valueSetted); editingControl.valueSetted += new LookupText.ValueSetted(productEditingControl_valueSetted); } }
public DataGridViewLookupColumn() { CellTemplate = new DataGridViewLookupCell(); }
public DataGridViewLookupColumn() { CellTemplate = new DataGridViewLookupCell(); ButtonText = "..."; }