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();
    }

10322 : The data in the bound datasource must be mangled before presentation. How?

Question

Because of the data in my normalized tables, when I use a databound gantt, no column in my DataTable has the data I would like to display in my GTP.NET grid.  I figured that I could use OnGridCustomCellDraw and OnGridPaintForeground to paint the cell much in the same way that I use the UserDraw, can I use these methods to draw the text in my Grid?

The problem I’m having is that the OnGridPaintForeground is the only event two that ever gets called, and based on the arguments given and the frequency it is called, I don’t think it is the appropriate for drawing the text for the grid column.

I must be missing some property that I need to set – similar to what you do with the TimeItemStyle when you are using UserDraw on TimeItems.

Are there any examples available where this is done?

Answer

One way is to produce a complex datasource that takes in the values from your other tables, but I think what you really want is a way to intercept what is put on the screen and also (if editable) a way to intercept what is put in the datarow when the grid is edited…

For this you need Grid.GridStructure.RootNodes.NodeDataConnect

There is currently no sample on this but the logic is the same as for time items (TimeItemDataConnect) and there are some samples for that…

Look at this article : http://plexityhide.dyndns.org/InstantKB13/article.aspx?id=10098

What you want to do is to implement the events:

Grid.GridStructure.RootNodes.NodeDataConnect.OnBeforeCellToDS
AND
Grid.GridStructure.RootNodes.NodeDataConnect.OnBeforeDSToCell

Once there you can do whatever you need with the data and fill the cells…