11093 : Calculated columns in a databound Grid

Question

 

I am using the OnBeforeDSToCell event to format some data to be displayed in the grid.  But I want one of my columns to be calculated based on two other columns – how can I do this?

 

Answer

 

Since the columns are filled from 0 to n, you cannot read the x+1 column when handling OnBeforeDSToCell for column x.< ?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

But I suggest that you get your data from the datasource instead:

 

    void NodeDataConnect_OnBeforeDSToCell(NodeDataConnect aNodeDataConnect, CellAndDSArgs args)
    {
      if (args.Cell.Column.Index==theCellCalclulatedFromTwoOtherValues)
        args.Value=(args.CurrencyManagerListItem as DataRowView).Row["Col1"].ToString()+(args.CurrencyManagerListItem as DataRowView).Row["Col2"].ToString();
    }

Leave a Reply