C#中datagridview单元格值改变实现模糊查找
public frmDepositEdit() { InitializeComponent(); dgvCardType.AutoGenerateColumns = false; dgvCardType.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dgvCardType_EditingControlShowing); } void dgvCardType_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { e.Control.KeyPress += new KeyPressEventHandler(Control_KeyPress); //委托行为 } //求实收金额。 decimal addMoney = 0; void Control_KeyPress(object sender, KeyPressEventArgs e) { //要处理的事件信息。 decimal intNumberBoxes = 0; decimal someAmount = 0; if (char.IsNumber(e.KeyChar)) { int column = dgvCardType.CurrentCellAddress.X; int row = dgvCardType.CurrentCellAddress.Y; if (column == 2) { string cellValue = Char.ToString(e.KeyChar); string test = dgvCardType[column, row].EditedFormattedValue.ToString(); test = test + cellValue; intNumberBoxes = Convert.ToDecimal(test); if (intNumberBoxes > 999) { e.Handled = true; } someAmount = decimal.Parse(dgvCardType.Rows[dgvCardType.CurrentCellAddress.Y].Cells[1].Value.ToString()); txt_现金金额.Text = (addMoney + intNumberBoxes * someAmount).ToString(); } } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步