Data Grid Displaying Superfluous Fields When Bound to a Collection of Entities

Posts   
 
    
David H
User
Posts: 100
Joined: 31-Dec-2004
# Posted on: 28-Oct-2010 06:13:20   

I am using a collection class to display a collection of entities in a grid. I am seeing two superfluous fields in the grid both coming from foreign keys of the specific table.

I am using LLBLGEN 3.0 from the October 26 release with VB.NET 9.0.

I attached the necessary materials to reproduce this. The project zip file includes a short read me file.

Please let me know what it is that I am doing wrong here.

Thanks

David

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Oct-2010 09:53:27   

Before examining the attached repro, could you please explain the problem in more details.

David H
User
Posts: 100
Joined: 31-Dec-2004
# Posted on: 28-Oct-2010 20:09:25   

I am getting extra fields displayed when binding a collection class to a data grid.

For instance, the sample I provided uses a collection class of Connector Entities generated for the Connector table of the database. The table has 5 fields and 2 foreign keys.

The foreign keys point to the Cable Drawing and Adapter tables.

Problem is that when I bind the collection to the grid by setting the datasource property to the collection class:

Private Sub _CableDrawingsGrid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles _CableDrawingsGrid.Click Dim entity As New isr.Cita.Data.EntityClasses.CableDrawingEntity If _CableDrawingsGrid.CurrentRow IsNot Nothing Then If entity.FetchUsingPK(CStr(_CableDrawingsGrid.CurrentRow.Cells(0).Value)) Then Me._ConnectorsGrid.DataSource = Nothing Me._ConnectorsGrid.DataSource = entity.Connectors End If End If End Sub

I see 7 columns.

Five columns match the table fields as expected. The two additional columns are superfluous and display the names of the two foreign entities pointed to by the foreign keys. For example, the title of the six column is Adapter (matching the name of the Adapter table) and the cells include the full name of the entity class associated with that table: isr.Cita.Data....Adapter.

I hope this makes the case clearer.

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Oct-2010 22:08:31   

This is kind of expected behaviour - grids us reflection to pick up the public properties of what they are bound to, and that includes the related entities. The grid has no idea that you don't want these displayed.

The usual option is to simply hide the columns you don't want to see.

Matt

David H
User
Posts: 100
Joined: 31-Dec-2004
# Posted on: 29-Oct-2010 02:03:14   

This does not sound like the whole story.

If that were the case the grid would show over 30 columns for properties such as IsDirty, IsNew, or ActiveContext. Yet, that is not the case.

My question essentially is what makes some properties bindable and others non-bindable?

David H
User
Posts: 100
Joined: 31-Dec-2004
# Posted on: 29-Oct-2010 03:53:03   

meanwhile I put together a simple workaround in case others find this thread relevant:


  ''' <summary>
  ''' Returns the list of field names
  ''' </summary>
  ''' <param name="entity">Reference to an entity implementing the <see cref="IEntity">entity interface</see></param>
  ''' <returns></returns>
  ''' <remarks></remarks>
  <Extension()> _
  Public Function GetFieldNames(ByVal entity As IEntity) As String()
    Dim l As New List(Of String)
    For Each field As IEntityField In entity.Fields
      l.Add(field.Name)
    Next
    Return l.ToArray
  End Function

  ''' <summary>
  ''' Hides columns that are not defined as entity fields.
  ''' </summary>
  ''' <param name="grid">The <see cref="DataGridView">grid</see></param>
  ''' <param name="entity">Specifies the entity displayed in the datagrid.</param>
  ''' <remarks></remarks>
  <Extension()> _
  Public Sub HideColumnsByEntityFields(ByVal grid As DataGridView, ByVal entity As IEntity)
    Dim fields As String() = entity.GetFieldNames()
    For Each column As DataGridViewColumn In grid.Columns
      If Not fields.Contains(column.Name) Then
        column.Visible = False
      End If
    Next
  End Sub

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Oct-2010 05:58:57   

David wrote:

My question essentially is what makes some properties bindable and others non-bindable?

Basically is the [Browsable(false)] attribute that is put on bind-irrelevant entity attributes, like IsDirty, IsNew, etc.

This is not set for related entity/collections as that is needed to navigate on grids that support multi level databinding.

The best approach is to design the grid at design-time so you have control on what exactly you want to show. Anyway, is good you found a workaround in your case.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 29-Oct-2010 14:01:37   

There's a setting for that. simple_smile

In v2.6 we had a setting called "HideManyOneToOneRelatedEntityPropertiesFromDatabinding". We removed that one in 3.0 in favor of our attribute and setting system. Because in fact all the setting did was emitting Browsable(false) on the navigator property.

In 3.0, we by default made these navigators hidden by applying a Browsable(false) attribute for a single-value navigator. In the designer, open project properties and go to code gen. meta-data defaults. Select 'NavigatorSingleValue' from the combo box and you'll see a Browsable() attribute definition. It's likely set to Browsable($true) in your case. If it's Browsable($false), go to the entity, open it in the editor, go to the code gen. info tab and select the navigator which is visible in the grid, and its 'Attributes' tab will have a Browsable($true) definition specified.

If you never want those to pop up, go to the project properties, code gen. meta-data defaults tab, NavigatorSingleValue and make sure Browsable($false) is specified. Then on the navigator, make sure the checkbox under 'Inherit' is checked for the navigator's Browsable($false) attribute definition in the code gen. info tab.

Then generate the code. This should give a <Browsable(False)> _ attribute on the property definitions in the entity classes which show up in the grid.

Frans Bouma | Lead developer LLBLGen Pro
David H
User
Posts: 100
Joined: 31-Dec-2004
# Posted on: 30-Oct-2010 03:04:22   

Setting Browsable($false) did the trick.

Thanks for the detailed 'navigation'. Notice however that I could not find "...the checkbox under 'Inherit...".

However, setting 'false' did propagate to the entity right away.

neilx
User
Posts: 267
Joined: 02-Nov-2007
# Posted on: 18-Mar-2011 11:42:43   

daelmo wrote:

David wrote:

My question essentially is what makes some properties bindable and others non-bindable?

This is not set for related entity/collections as that is needed to navigate on grids that support multi level databinding.

This is wrong. The Browsable(false) is set by default on these entities.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Mar-2011 19:09:55   

neilx wrote:

daelmo wrote:

David wrote:

My question essentially is what makes some properties bindable and others non-bindable?

This is not set for related entity/collections as that is needed to navigate on grids that support multi level databinding.

This is wrong. The Browsable(false) is set by default on these entities.

Browsable(false) is 'by default' set on m:1 properties. It's not set 'by default' on EntityCollection<xyz> properties.

David Elizondo | LLBLGen Support Team