Adding Calculated field to TypedView

Posts   
 
    
Posts: 11
Joined: 29-Oct-2008
# Posted on: 10-Sep-2010 06:01:54   

Hi All,

Must be mising something obvious here, help! Trying to add a calculated column to a typed view. The calculation needs to be done in code, not an sql aggreagate function. All the examples I find are using SQL agregate functions.

I have added a new column to the partial class for the typed view and added the column property. Also added the code to do the calculation. All this works, how do I get it to update the column in the underlying datatable so I can bind it to a grid?

I can do it after the Fill is done with a loop, I was hoping there was a way to do it within the TypedView and not the presentation code.

Thanx Colin...



  Partial Public Class DksdirecommunicationTypedView
        Dim _columnECommunications As DataColumn

        Protected Overrides Sub OnInitialized()

            _columnECommunications = New DataColumn("eCommunications", GetType(System.String), Nothing, MappingType.Element)
            _columnECommunications.ReadOnly = False
            _columnECommunications.Caption = "eCommunications"
            Me.Columns.Add(_columnECommunications)

            MyBase.OnInitialized()

        End Sub

        Friend ReadOnly Property eCommunications As DataColumn
            Get
                Return _columnECommunications
            End Get
        End Property

    End Class



    Partial Public Class DksdirecommunicationRow

        Public ReadOnly Property ECommunicationss As String
            Get

                Select Case Me.Methodtype
                    Case AXDatabase.EntityClasses.Base_Enum.DirECommunicationMethodType.Email
                        Return Me.Email
                    Case AXDatabase.EntityClasses.Base_Enum.DirECommunicationMethodType.Phone
                        Return Me.Phone
                    Case AXDatabase.EntityClasses.Base_Enum.DirECommunicationMethodType.Telex
                        Return Me.Telex
                    Case AXDatabase.EntityClasses.Base_Enum.DirECommunicationMethodType.URL
                        Return Me.Url
                    Case Else
                        Return ""
                End Select
            End Get
        End Property

    End Class

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Sep-2010 07:16:55   

So it worked if you fill outside, but you want to calculate it inside the TypedList? Is that it?

David Elizondo | LLBLGen Support Team
Posts: 11
Joined: 29-Oct-2008
# Posted on: 10-Sep-2010 21:59:48   

Correct! It works in a loop if I run after the fill has completed. I want it to happen inside the fill so the presentation code doesn't need to do it. Example of presentation code is below.


            Dim responsibilities As New DksdirecommunicationTypedView
            Dim filter As New PredicateExpression
            filter.Add(DksdirecommunicationFields.Dataareaid = Vendor.Dataareaid)
            filter.AddWithAnd(DksdirecommunicationFields.Partyid = CStr(e.Row.DataKeyValue))
            responsibilities.Fill(0, Nothing, False, filter)

            Dim responsibility As DksdirecommunicationRow
            For Each responsibility In responsibilities
                responsibility.Item("eCommunications") = responsibility.ECommunicationss
            Next

            'show them
            e.ChildDataSource = responsibilities


Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Sep-2010 10:28:06   

It's right to do the calculations after the Fill method, what is somehow misplaced is the call to the Fill method itself.

IMHO the Fill method and the calculations done afterwards sould be in a middle layer (Business Layer), not inside the Presentation Layer.