c# - 用户删除后如何从DataGridview获取行数据
问题描述
我正在为一家商店工作,并使用 DataGridView 来存储所有客户订单并不断更新总价。当他轻松订购更多商品时,我会更新价格。当我删除一个特定的项目时,我也需要知道它的数据来更新总价。
所以我需要该行的内容来进行我需要的更改。
当他添加更多项目时,这就是我用来更新总价的方法:
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(pill);
row.Cells[2].Value = name;
row.Cells[1].Value = price;
row.Cells[0].Value = quantity;
pill.Rows.Add(row);
totalPrice += price * quantity;
total.Text = totalPrice.ToString();
解决方案
有一个事件叫UserDeletingRow
. 它接受DataGridViewRowCancelEventArgs
包含用户删除的行。
您需要做的是订阅此活动,并从那里更新您的价格。
推荐阅读
- tree - 使用 HyperGraphQL 检索父母和孩子
- rest - 通过 REST api (v2) 将文章发布到公司 LinkedIN 页面
- spring-boot - 当从控制器启动的作业失败时,如何防止弹簧批处理关闭应用程序?
- django - 在 Django 部署期间配置不正确的 urls.py (Django 2.1)
- websocket - Websocket 握手:“Sec-WebSocket-Accept”标头值不正确
- python - Numpy:将列表转换为方形数组
- python - Python中具有不同签名的钻石继承
- css - React-Bootstrap 的 Select 元素的验证未对齐
- xml - 如何防止 CXF 转换 %gt; 到 > 在有效载荷中?
- c# - Linq .ToList() 和 SqlQuery 的数据并发问题