Set A DevExpress RepositoryItemLookupEditor to Display Text From A Referenced Table

That’s what a LookupEditor is intended for: display text from another table that is referenced by an external key.

public RepositoryItemLookUpEdit GetRepositoryEditorLookup(T element)
     var rep = new RepositoryItemLookUpEdit();
     if (_entities == null) { return null; }
     var set = _entities.CreateObjectSet();       // create the list of objects of type T
     rep.DataSource = set;                           // set this list as datasource for the lookup
     rep.ValueMember = ReferenceFieldId;             // set the field name that is referenced in the external key
     rep.DisplayMember = ReferenceFieldName;         // set the field name to display
     rep.Name = EditorName;                          // the name of the editor to be used in code
                                       // ReferenceCaption = the nae to be displayed in the lookup
     rep.Columns.Add(new LookUpColumnInfo(ReferenceFieldName) { Caption = ReferenceCaption });       
     rep.Columns[ReferenceFieldName].SortOrder = ColumnSortOrder.Ascending;

     rep.TextEditStyle = TextEditStyles.DisableTextEditor;   // don't want the text to be editable here

            // create a button '+' if we have a ProgramNew handed over in the class' constructor (not shown here)
            // in this case we would need to listen to the ButtonClick event of the editor
     if (ProgramNew != null)
         var edit = new EditorButton(ButtonPredefines.Plus);     
     return rep;

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert