Home Forums WinForms controls Xceed Grid for WinForms How to add calculated column? Reply To: How to add calculated column?

User (Old forums)
Post count: 23064

1: add an unbound column to the grid: via the designer, or with this code:<code>Column calculatedColumn = new Column(“calculatedColumn”, typeof(int)); // use a different type if necessary
grid.Columns.Add(calculatedColumn);</code>2: attach an event-handler to the ValueChanged event of the cells:<code>EventHandler handler = new EventHandler(cellValueChanged);
foreach(Cell cell in grid.DataRowTemplate.Cells)
if (cell.ParentColumn != calculatedColumn)
cell.ValueChanged += handler;</code>3: write the event-handler method:<code>private void cellValueChanged(object sender, EventArgs e) {
Cell cell = sender as Cell;
if (cell != null) {
CellRow row = cell.ParentRow;
row.Cells[calculatedColumn.Index].Value = <i>calculated from the other cells of the row</i>;

Imported from legacy forums. Posted by Tommy (had 3289 views)