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!