如何根据DatagGridView中绑定列的值计算未绑定列的值?
我的 DataGridView 中有几列,其中一列是未绑定的列,并且 DataGridVIew 处于虚拟模式。
当调用 CellValueNeeded
事件时,我想根据有界内的 Cells[2]
的值计算 Cells[0]
的值列到底层DataSource
。
这就是我尝试执行此操作的方式:
private void dgvItems_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
e.Value = dgvItems.CurrentRow.Cells[2].Value * 5; //simplified example
}
但是,我收到 System.StackOverflowException
因为它接缝调用 dgvItems.CurrentRow.Cells[2].Value
导致调用到另一个 CellValueNeeded 事件。依此类推...但是 Cells[2] 不是未绑定的列,因此根据常识,它不应该导致递归调用,除非获取任何列(绑定或未绑定)的值触发该事件...
我可以此处不使用 SQL 表达式,并且我无法在任何 SQL 调用中预先计算 e.Value。在实际示例中,Cells[2].Value 是 HashTable 中使用的键,它将返回 Cells[0] (e.Value) 的正确值。
我能做些什么?
I have few columns in my DataGridView, one of them is an unbound column and the DataGridVIew is in VirtualMode.
When CellValueNeeded
event is called, I want to calculate value of Cells[0]
basing on the value of Cells[2]
which is in bounded column to the underlaying DataSource
.
This is how I try to do this:
private void dgvItems_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
{
e.Value = dgvItems.CurrentRow.Cells[2].Value * 5; //simplified example
}
However, I am getting System.StackOverflowException
because it seams that call to dgvItems.CurrentRow.Cells[2].Value
results in call to another CellValueNeeded event. And so on and so on... However Cells[2] is not an unbound column, so on common sense it should not result in recursive call unless getting value of any column(bound or unbound) firest that event...
I can not use here SQL Expression and I can not precalculate e.Value in any SQL call. In real example Cells[2].Value is a key used in HashTable which will return a correct value for the Cells[0] (e.Value).
What can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要有选择性并仅对第 0 列执行操作:
You need to be selective and act on column 0 only: