Databinding to WinForms Grid using SelfServicing

Posts   
 
    
Posts: 77
Joined: 05-May-2005
# Posted on: 11-Aug-2005 15:54:08   

Hi. I am using the Self Servicing code and I'm trying to bind a collection to a WinForms standard datagrid using a custom table style to display only the Id from the root entity in the collection plus a name from an entity with a 1:1 relation to the root entity. I cannot get the mapping name right on the related field. Here's my code - what am I doing wrong?


' this is a 1:1 relationship from EmployeeFloatHistory.EmployeeId to SecEmployee.EmployeeId
Dim path As PrefetchPath = New PrefetchPath(CType(EntityType.EmployeeFloatHistoryEntity, Integer))
path.Add(EmployeeFloatHistoryEntity.PrefetchPathSecEmployee)

' i have verified that the prefetch works so that the SecEmployee entity is indeed correctly loaded for each history record
Dim floatHistoryCollection As EmployeeFloatHistoryCollection = New EmployeeFloatHistoryCollection
floatHistoryCollection.GetMulti(Nothing, path)
        
' this is a standard WinForms grid
grid.DataSource = floatHistoryCollection

Dim mainStyle As New DataGridTableStyle
mainStyle.MappingName = floatHistoryCollection.GetListName(Nothing)

Dim TextCol As DataGridTextBoxColumn

' when the grid displays, this column does show up (property = EmployeeFloatHistoryEntity.EmployeeId)
TextCol = New DataGridTextBoxColumn
TextCol.MappingName = "EmployeeId"
TextCol.HeaderText = "Employee Id"
mainStyle.GridColumnStyles.Add(TextCol)

' when grid displays, this column does not show up (property = EmployeeFloatHistoryEntity.SecEmployee.LastName
' I have also tried other variations (see commented code) trying to get at this property - none worked
TextCol = New DataGridTextBoxColumn
'TextCol.MappingName = "SecEmployee.LastName"
'TextCol.MappingName = "EmployeeFloatHistoryCollection.SecEmployee.LastName"
'TextCol.MappingName = "SecEmployeeEntity.LastName"
TextCol.MappingName = "EmployeeFloatHistoryCollection.SecEmployeeEntity.LastName"
TextCol.HeaderText = "Employee Last Name"
mainStyle.GridColumnStyles.Add(TextCol)

grid.TableStyles.Add(mainStyle)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 12-Aug-2005 09:44:51   

That's not going to work, as related items in a grid, also have to be collections. What you should do is add a field mapped onto related field in the LLBLGen Pro designer, in the entity editor while editing EmployeeFloatHistory entity. Then you'll have the related field in the same list in the grid, as the field is part of the EmployeeFloatHistory entity's property list simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 77
Joined: 05-May-2005
# Posted on: 12-Aug-2005 16:11:28   

I hoped that perhaps there was a way to do this without altering the entity in the designer, but it would probably be just as easy to create a typed list since this was a very simplified example to express the problem and the data in the grid needs to be read only anyway. Thanks for your speedy reply. simple_smile