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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14214 |

    How to add calculated column which is calculate from the value of columns?

    Imported from legacy forums. Posted by aixllxia (had 2072 views)

    User (Old forums)
    Member
    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>;
    }
    }</code>

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.