Databinding a custom entitycollection to a combobox not working..

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 03-Mar-2009 17:37:29   

Hi

I am having some problems with my custom entity collection and binding it.

I have called an entitycollection in the normal way but to save going back and for to the database as it is done by webservices I want to filter it locally.

Here's my code for creating the collection: Main elements is the one called directly from the DB


EntityCollection FilteredElements = new EntityCollection();
 IPredicateExpression Filter = new PredicateExpression(ElementFields.GroupID == Id);
List<int> ElementsIndexes = MainElements.FindMatches(Filter);
 foreach (int index in ElementsIndexes )
            {
                FilteredElements.Add((ElementEntity)MainElements[index]);
            }

I am then binding it to a Win forms RadComboBox by doing the following:

 DropDown.DisplayMember =ElementFields.Name.Name;
           BindingTypeDropDown.DropDown.ValueMember =ElementFields.Value.Name;
           BindingTypeDropDown.DropDown.DataSource = FilteredElements;

The problem is when I bind it to my dropdown all I get is a repeated list of "EntityClasses.ElementEntity"

If I put the MainElements entitycollection as the datasource it all works ok.

What am I doing wrong? I have been pulling my hair out all afternoon!

Thanks

Bex

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Mar-2009 21:27:14   

Does it help if you set the DataSource first, and then the DisplayMember and ValueMember properties afterwards ?

Where does ElementFields come from...? and are you sure the values in it are case sensitive matches for your property names ?

Matt

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 04-Mar-2009 10:03:11   

Hi Matt

Telerik Says you need to set the data source afterwards to speed it up, but I have tried both ways round and botht have the same results.

Element fields comes from the main elements table (sorry mistyped when I copied it across).

I have tried typing "value" and "name" as the displaymemember rather than using elementfields.Value.Name etc but made no difference.

Thanks

Becky

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Mar-2009 11:08:59   

What happens if you repeat these steps with the defacto combobox?

Also why don't you try using a bindingSource control as your middle guy?

BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 04-Mar-2009 11:25:45   

Hi Walaa

It does the same with the normal combobox aswell and when using the bindingsource variable, and it still works with the original entitycollection..

I now have my boss on my back telling me to hurry up so I have resorted for the time being to looping the newly created entity collection like so:


  foreach (ElementEntity elementEntity in ElementCollection)
            {
                RadComboBoxItem item = new RadComboBoxItem(elementEntity.Name, elementEntity.Value);
                combo.Items.Add(item);
            }


I really would like to know why I cannot bind it in the usual way though!

Thanks bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Mar-2009 11:38:33   

Are you using Adapter or SelfServicing?

EntityCollection FilteredElements = new EntityCollection();

Most probably because you are using an un-typed entityCollection, no entityFactory or type specified.

Also, why don't you use an entityView like so:

EntityView FilteredElements = new EntityView(MainElements);

IPredicateExpression Filter = new PredicateExpression(ElementFields.GroupID == Id);
customerView.Filter = Filter;

DropDown.DisplayMember =ElementFields.Name.Name;
BindingTypeDropDown.DropDown.ValueMember =ElementFields.Value.Name;
BindingTypeDropDown.DropDown.DataSource = FilteredElements; 
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 04-Mar-2009 11:50:20   

Hi Walaa

Thanks for the very quick replies..

I am using adapter and its version 2.6 (sept 12th 2008 ) ..

I tried setting the type of the entitycollection with the new EntityFactory but it also made no difference..

I did not know you could use an entityview for this, athough when I type "EntityView myView.." I get a red squiggle under "EntityView" saying

incorrect number of paramenters in reference class 'SD.LLBLGen.Prd.ORMSupportClasses.EntityView<TEntity>'

Do I need a different reference? Or do I just need to read up on it?

Thanks

Bex

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 04-Mar-2009 11:57:02   

For Adapter you should use this:

EntityView<MainEntity> FilteredElements = new EntityView<MainEntity>(MainElements);

Another example for clarification:

EntityView<CustomerEntity> customerView = new EntityView<CustomerEntity>(customers);
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 04-Mar-2009 12:20:14   

Thanks Walaa.

I shall try using the EntityView this afternoon and see how it goes!