Data binding

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 26-May-2010 07:32:21   

Hello

I just tried binding datasource to combo box. But it does not display any data in runtime.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-May-2010 07:38:27   

Did you fetch the involved collection? How your behind code looks like? (In general, more info please http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7725)

David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-May-2010 10:56:18   

I managed to get it. But is this the right way of doing it since I am fetching only one entity

var countrydatasource = new EntityCollection(new CountryEntityFactory()); var countrydatasourceadapter = new DataAccessAdapter(); var bucket = new RelationPredicateBucket();

        bucket.PredicateExpression.Add(CountryFields.Flag == 0); // Filter by flag = 0
        countrydatasourceadapter.FetchEntityCollection(countrydatasource, bucket); //retrieve data from table country
        countrydatasource.Sort((int)CountryFieldIndex.Description, ListSortDirection.Ascending); //sort data by description in ascending order
        cmbcountryid.DataSource = countrydatasource;
        cmbcountryid.ValueMember = "COUNTRYID";
        cmbcountryid.DisplayMember = "DECRIPTION";
        cmbcountryid.SelectedIndex = -1;
        countrydatasourceadapter.CloseConnection(); // close connetion

regards,shekar

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-May-2010 11:15:15   

This code is valid. Although it can be enhanced a little but the idea is correct.

But you are not using the bindingSource control (bindingSourceCountry) which is recommended.

And you can use design time databainding to visually bind the binding source to the entityCollection and the comboBox to the bindingSource, and set the dataMember and ValueMember too. This is just an artifact which will write the appropriate code for you.

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-May-2010 12:08:58   

Walaa wrote:

But you are not using the bindingSource control (bindingSourceCountry) which is recommended.

Thank you so much for confirming i got it rigt. Any example of bindingSource control

shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 28-May-2010 12:46:22   

Ignore my message. I got it. Thanks