Gridlookupedit Entity Framework

202 Views Asked by At

how can i fill the gridlookupedit correctly?.
I can not find the error.

Method fill gridlookupedit

    public void CargaGLEVerdadero()
    {
        pcbjEntidades contexto = new pcbjEntidades();
        IList consultaModeloInsumosVerdadera = (from ModeloInsumoes in contexto.ModeloInsumoes
                                                where
                                                  ModeloInsumoes.Activo == true
                                                select new
                                                {
                                                    ModeloInsumoes.NombreModeloInsumo
                                                }).ToList();

        gleNombreModelo.Properties.DataSource = new BindingSource(consultaModeloInsumosVerdadera, "");
    }

Construct of form

public frmAgregarMarca()
    {
        InitializeComponent();
        CargaGLEVerdadero();
    }

Result

1

There are 1 best solutions below

0
On

This issue does not related to GridLookup directly rather the to the EF/Winforms interoperation.

Since you are using DevExpress, you can use the Data Source Configuration Wizard.This feature is available for any data-aware control in threir suite and it knows how to do the things correctly and it can make all the work for you:

// This line of code is generated by Data Source Configuration Wizard
// Instantiate a new DBContext
WindowsFormsApplication2.CountriesDBEntities dbContext = new WindowsFormsApplication2.CountriesDBEntities();
// Call the Load method to get the data for the given DbSet from the database.
dbContext.Countries.Load();
// This line of code is generated by Data Source Configuration Wizard
gridLookUpEdit1.Properties.DataSource = dbContext.Countries.Local.ToBindingList();

Then you can customize Wizard's output:

dbContext.Countries.Where(c => c.Capital.StartsWith("A")).Load();