首页 > 解决方案 > 用户删除后如何从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();

标签: c#desktop-application

解决方案


有一个事件叫UserDeletingRow. 它接受DataGridViewRowCancelEventArgs包含用户删除的行。

您需要做的是订阅此活动,并从那里更新您的价格。


推荐阅读