Current filter:
                                You should refresh the page.

                                How to create a data source wrapper that adds an empty item to the lookup list

                                0

                                This example demonstrates how to display an empty (blank) item in the dropdown list of the LookUpEdt control. This approach is also applicable to GridLookUpEdit / RepositoryItemGridLookUpEdit.

                                See Also:
                                How to clear the currently selected value in the LookUp editor

                                You must  log in  or  register  to leave comments
                                Select file
                                • Form1.cs
                                • Program.cs
                                • DataSourceWithEmptyItem.cs
                                Select language
                                • C#
                                • VB.NET
                                Select version
                                • v2008 vol 2.7 - v2012 vol 2.7
                                using System;
                                using System.Collections.Generic;
                                using System.ComponentModel;
                                using System.Data;
                                using System.Drawing;
                                using System.Text;
                                using System.Windows.Forms;
                                using DevExpress.Xpo;
                                using DevExpress.XtraEditors;
                                
                                namespace LookUpListWithNullEntry {
                                    public partial class Form1 : Form {
                                        public Form1() {
                                            InitializeComponent();
                                
                                            FillData();
                                
                                            this.repositoryItemLookUpEdit1.DataSource = new DataSourceWithEmptyItem(this.xpc2);
                                        }
                                
                                        private void FillData() {
                                            if(xpc2.Count == 0) {
                                                Lookup lookup = new Lookup();
                                                lookup.Description = "Description 1";
                                                lookup.Save();
                                                xpc2.Add(lookup);
                                            }
                                        }
                                
                                        private void repositoryItemLookUpEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) {
                                            if(e.Button.Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Delete) {
                                                LookUpEdit editor = (LookUpEdit)sender;
                                                editor.CancelPopup();
                                                editor.EditValue = null;
                                            }
                                        }
                                    }
                                
                                    public class Main : XPObject {
                                        public string Name;
                                        public Lookup Description;
                                    }
                                
                                    public class Lookup : XPObject {
                                        public string Description;
                                    }
                                }