繁体   English   中英

datagridview行单元格值

[英]datagridview row cell value

我在网上搜索答案但没有找到答案。 这是C#winforms。 有可能做这样的事情:

private void datagridItems_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int ID;
DataGridViewRow row = this.datagridItems.Rows[e.RowIndex];
DataGridViewCell cell = row.Cells[e.ColumnIndex];

if (row.Cells[2].Value == some value)
{
//set the value of a cell
row.Cells[4].Value = new value;
}
}

我需要根据单元格[2]中的其他一些标准清除单元格[4]的现有内容。

谢谢你的帮助。 瑞安

如果DataGridView是数据绑定,则不应直接修改单元格的内容。 相反,您应该修改数据绑定对象。 您可以通过DataGridViewRow的DataBoundItem访问该对象:

MyObject obj = (MyObject)dataGridView.CurrentRow.DataBoundItem;
obj.MyProperty = newValue;

如果绑定对象不支持INotifyPropertyChanged事件,则在之后刷新网格。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM