How to get a single entity into the toolbox?

Posts   
 
    
mario.muja avatar
mario.muja
User
Posts: 37
Joined: 03-May-2005
# Posted on: 25-Feb-2006 16:34:13   

In an earlier post, I have read the advice to set a single entity as the datasource for a BindingSource to make column definitions available for a grid on the same form.

How can this be done? I do not manage to get single entities into the toolbox. Thus, how can they then be used as a datasource of a BindingSource using the Designer? If I try to add my generic DLL to the toolbox, the only thing that shows up is the type EntityCollection.

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 26-Feb-2006 06:10:56   

Hi BindingSource can be bound to any of the following: - IEnumerable - ICollection - IList - IListSource - IBindingList - IBindingListView but not to a single single entity.

One way , perhaps is to add it into a collection, but not sure or

You can arbitrarily set the DataSource of BindingSource to any System.Object. When this is done, BindingSource internally creates a BindingList<T> of that Object type and adds the item to this list. You can then add objects to this list by calling BindingSource.Add(…).

e.g. Say you have a Customer object. You can do the following: BindingSource bs = new BindingSource(); bs.DataSource = new Customer(); This will create a BindingList<Customer> internally with one object.

I hope I have read your query correctly and not leading you down the wrong path.

Apologies if I am and please come back.

mario.muja avatar
mario.muja
User
Posts: 37
Joined: 03-May-2005
# Posted on: 26-Feb-2006 20:54:57   

I am referring to the following discussion:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=5274&HighLight=1

There you will find the following confirmation that bindingSource has been bound to a single entity at design time:

"4) are you saying that you assign a SINGLE "entity" to the bindingSource? At design time - so the binding source knows the fields."

My original issue is that I want DataGridView to show columns automatically without the need to define each column manually with a proper DataPropertyName.

Thus, if they managed to assign a single entity as the datasource of a BindingSource, how did they do it? You say that it is not possible but the two guys from the discussion named above seem to have it done.

mario.muja avatar
mario.muja
User
Posts: 37
Joined: 03-May-2005
# Posted on: 26-Feb-2006 21:14:31   

The problem is solved now. What you have shown in code can be done in the designer in the following way:

  • navigate to the Datasource property of a BindingSource in Designer
  • select "Add Project Datasource"
  • select "Object" as the datasource type
  • select the LLBLGEN entity type

This is what I searched for. Now everything works as expected and my DataGridView automatically created the column definitions. Thanks for the BindingList<T> tip!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Feb-2006 21:50:15   

Be sure to bind a new instance of an entitycollection at runtime though. If you inspect the vs.net generated code, you'll see the bindingsource's datasource is set to a TYPE.

Frans Bouma | Lead developer LLBLGen Pro
JimHugh
User
Posts: 191
Joined: 16-Nov-2005
# Posted on: 26-Feb-2006 22:27:43   

I drag an EntityCollection from the toolbox, rename it, set it's factory and SupportsSorting = true.

Then I drag a BindingSource and set it's DataSource to the EntityCollection instance

Then I drag a DataGridView and set it's DataSource to the BindingSource instance.

All of the columns are setup correclty for me.

VS2005 ,LLBLGEN 1.2005.1

Following code snipped from *.Designer.vb


        Friend WithEvents ecCustomer As HTI.FFBL.HelperClasses.EntityCollection

        Me.BindingSource1.DataSource = Me.ecCustomer
        '
        'ecCustomer
        '
        Me.ecCustomer.ActiveContext = Nothing
        Me.ecCustomer.AllowEdit = True
        Me.ecCustomer.AllowNew = True
        Me.ecCustomer.AllowRemove = True
        Me.ecCustomer.Capacity = 0
        Me.ecCustomer.ConcurrencyPredicateFactoryToUse = Nothing
        Me.ecCustomer.DoNotPerformAddIfPresent = True
        Me.ecCustomer.EntityFactoryToUse = New HTI.FFBL.FactoryClasses.CustomerEntityFactory
        Me.ecCustomer.EntityValidatorToUse = Nothing
        Me.ecCustomer.IsReadOnly = False
        Me.ecCustomer.SupportsSorting = True
        Me.ecCustomer.ValidatorToUse = Nothing