How to clear items in DevExpress LookupEdit

15.9k Views Asked by At

Hai, Am using DevExpress LookupEdit in C#.NET application.I want to clear all items in the LookupEdit.Please help

code:

lkpLabItem.Properties.DataSource = null; 
         lkpLabItem .Properties.DataSource = _lab.selectChemicals ();
         lkpLabItem.Properties.DisplayMember = "labitem_Name";
         lkpLabItem.Properties.ValueMember = "labItem_ID";
         lkpLabItem.Properties.BestFitMode = BestFitMode.BestFit;
         lkpLabItem.Properties.SearchMode = SearchMode.AutoComplete;

         lkpLabItem.Properties.Columns.Add(new LookUpColumnInfo("labitem_Name", 100, "Lab Items"));
         lkpLabItem.Properties.AutoSearchColumnIndex = 1;

Thank you.alt text

2

There are 2 best solutions below

0
On BEST ANSWER

Got items correctly.

problem is that am creating `LookUpColumnInfo whenever am calling same method. code:

lkpLabItem.Properties.DataSource = null; 
         lkpLabItem .Properties.DataSource = _lab.selectChemicals ();
         lkpLabItem.Properties.DisplayMember = "labitem_Name";
         lkpLabItem.Properties.ValueMember = "labItem_ID";
         lkpLabItem.Properties.BestFitMode = BestFitMode.BestFit;
         lkpLabItem.Properties.SearchMode = SearchMode.AutoComplete;

create LookUpColumnInfo only first time then call method without LookUpColumnInfo

4
On

LookupEdit is mean to provide list of data from the linked datasource, so, to clear the items you can set its DataSource property to null:

lookUpEdit1.Properties.DataSource = null;

or, if you are using a BindingSource as the LookupEdit data source, you can set its DataSource property to null.