I’ve a simple table with only one column UrzadSkarbowyWojewodztwo that I’m trying to attach Entity Framework query to ComboBoxEdit or LookUpEdit (preferably both for reference). Can somebody share a a way to do this considering that I don’t want do it from GUI?
I tried multiple ways and it’s simply failing every time. I’m sure I’m missing something…
using (var context = new EntityBazaCRM(Settings.sqlDataConnectionDetails))
{
IQueryable<UrzedySkarboweWojewodztwa> listaWojewodztw = from d in context.UrzedySkarboweWojewodztwas
select d;
//lookUpEdit1.DataBindings.Add("EditValue", listaWojewodztw, "", true);
lookUpEdit1.DataBindings.Add("EditValue", listaWojewodztw, "UrzadSkarbowyWojewodztwo", true);
lookUpEdit1.Properties.DataSource = listaWojewodztw.ToList();
lookUpEdit1.Properties.DisplayMember = "UrzadSkarbowyWojewodztwo";
lookUpEdit1.Properties.ValueMember = "UrzadSkarbowyWojewodztwo";
LookUpColumnInfo col = new LookUpColumnInfo("UrzadSkarbowyWojewodztwo", "Województwo", 100) { SortOrder = DevExpress.Data.ColumnSortOrder.Ascending };
lookUpEdit1.Properties.Columns.Add(col);
To be able to bind Entity Framework list with DevExpress ComboBoxEdit one needs to create additional
partialclass which has the same name as theobjectwe’re trying to put intoComboBoxEdit. Into that class we need to put an override on theToString()for value we want to display in the ComboBoxEdit for the user.Then we simply assign objects to the
ComboBoxItemCollectionand Devexpress will do the rest.