views:

852

answers:

2

In Excel I can use an expression like "=C16+C17" for a cell to display values from other cells.

In my application I need something similar. The user needs to be able to select a range of cells from a databound grind and display the sum in another cell (not in a footer!). So what I need is the ability to assign something like "Take the values from column xyz from the records identified by ids 7, 23, 42 and sum them up" to an arbitrary cell.

Does anyone know a component that offers such an "expression language"?

+2  A: 

There's nothing built into the DataGridView that can help you do that. Your option is obviously Custom Controls. I'm sure Infragistics UltraGrid has something like that, but in case you don't want to spend the money, you could roll your own. It might actually not be that hard. Here's the simple way to do it.

Always bind your datagridview to a DataTable, and then when you want to add the expression, you add a new DataColumn and set the Expression property. Here's some info on the DataColumn's expression property. From MSDN

We've done something similiar to that at work and it actually works quite well. Good luck!

BFree
+1  A: 

I'm going to go with this CodeProject article: "Implementing an Excel-like formula engine". It has a parser, formula evaluation and it's quite easy to connect it with a datagrid.

longeasy