Binding inner entity property to a grid

Posts   
 
    
Al
User
Posts: 4
Joined: 11-May-2004
# Posted on: 14-May-2004 09:38:01   

Hi,

I want to bind an EntityCollection to a Win-Forms DataGrid. Each entity of the collection contains another entity by relation (m:1). My aim is to bind a field of the inner entity to the grid.

I tried as MappingName for the DataGridTextBoxColumn

"PropertyNameOfInnerEntity.PropertyName"

, but there was no column shown.

Have I done anything wrong? If not, is there a way to handle such situations?

Thanks for help.

Al

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-May-2004 09:47:43   

You could add a property to the derived entity class and that property calls into the related entity's property.

Frans Bouma | Lead developer LLBLGen Pro
KyleJ
User
Posts: 4
Joined: 14-Mar-2005
# Posted on: 14-Mar-2005 01:18:00   

Could you expand more on this?

I've got a Northwinds Product/Category entity collection that I'm trying to display in a datagrid.

Here's my code:


Private myProducts As EntityCollection

Private Sub frmProducts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    '
End Sub

Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
    LoadProducts()
    Bind()
End Sub

Private Sub LoadProducts()
    Dim adapter As DataAccessAdapter
    Try
        adapter = New DataAccessAdapter

        myProducts = New EntityCollection(New ProductEntityFactory)
        Dim prefetchPath As IPrefetchPath2 = New PrefetchPath2(CType(EntityType.ProductEntity, Integer))
        prefetchPath.Add(ProductEntity.PrefetchPathCategory)

        adapter.FetchEntityCollection(myProducts, Nothing, prefetchPath)
    Catch ex As Exception
    Finally
        adapter.CloseConnection()
    End Try
End Sub

Private Sub Bind()
    dg.TableStyles.Clear()
    dg.TableStyles.Add(BuildDataGridTableStyle)
    dg.DataSource = myProducts
End Sub

Private Function BuildDataGridTableStyle() As DataGridTableStyle
    Dim myTableStyle As New DataGridTableStyle

    '--- Col 1 ---
    Dim myCol1 As New DataGridTextBoxColumn
    With myCol1
        .HeaderText = "Product ID"
        .MappingName = "ProductID"
        .Width = 100
    End With
    myTableStyle.GridColumnStyles.Add(myCol1)

    '--- Col 2 ---
    Dim myCol2 As New DataGridTextBoxColumn
    With myCol2
        .HeaderText = "Product Name"
        .MappingName = "ProductName"
        .Width = 100
    End With
    myTableStyle.GridColumnStyles.Add(myCol2)

    '--- Col 3 ---
    Dim myCol3 As New DataGridTextBoxColumn
    With myCol3
        .HeaderText = "Category ID"
        .MappingName = "CategoryID"
        .Width = 100
    End With
    myTableStyle.GridColumnStyles.Add(myCol3)

    '--- Col 4 ---
    Dim myCol4 As New DataGridTextBoxColumn
    With myCol4
        .HeaderText = "Category Name"
        .MappingName = "Category.CategoryName"
        ''''''''.MappingName = "Category"
        ''''''''.MappingName = "CategoryName"
        .Width = 100
    End With

    myTableStyle.GridColumnStyles.Add(myCol4)

    Return myTableStyle
End Function


Everything works great except for the Category.CategoryName column. How do I get the related entity's fields to display in the grid?

Thanks for your help!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Mar-2005 12:04:20   

For demo users, the derived entity classes for adapter aren't available, so adding that code to the current entities is a bit problematic. This will be addressed in hte 1.0.2004.2 release. In the meantime, use a typed list for this.

Frans Bouma | Lead developer LLBLGen Pro