How to calculate unbound column value based on value of bound colum in DatagGridView?

Posted by Wodzu on Stack Overflow See other posts from Stack Overflow or by Wodzu
Published on 2010-05-27T18:56:56Z Indexed on 2010/05/27 19:11 UTC
Read the original article Hit count: 328

Hi.

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about datagridview