gpt4 book ai didi

c# - 如何在 DataGridview 中更改一个单元格的值以更改其他单元格的值

转载 作者:行者123 更新时间:2023-12-05 04:15:20 29 4
gpt4 key购买 nike

例如:如果我正在更改 MRP 列,它应该将该值与另一个名为 No_of_Units 的列值相乘,结果应该存储在名为 的列中>总计,提前致谢

最佳答案

你的意思是这样的?

private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == index of column MRP)
{
int value = (int)DataGridView1.Rows[e.RowIndex].Cells["NO_OF_UNITS"].Value * (int)DataGridView1.Rows[e.RowIndex].Cells["MRP"].Value;
DataGridView1.Rows[e.RowIndex].Cells["TARGET_COLUMN"].Value = value;
}
}

这个答案是简化的,您可能需要一些额外的检查,比如检查空值和类似的东西。但它应该让你上路。

在你的评论中你问:

How to get the index of column MRP ?

单击数据网格。找到属性列并单击列列表中的小按钮,找到列 MRP 并复制名称属性。这可能是 MRP,但也可能是 DataGridColumn1 之类的。

假设名称属性是“MRP”,你可以这样做:

if (e.ColumnIndex == MRP.ColumnIndex)

关于c# - 如何在 DataGridview 中更改一个单元格的值以更改其他单元格的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32482207/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com