How to add a lookupedit editor to a Devexpress Xtragrid’s column

Ingredients:
  • Developer Express 2010 or above
  • An Xtragrid control + Xtragrid view
  • Two database tables: one displayed in the Xtragrid control and one displayed in the look up edit column of the Xtragrid
  • VS 2008 with CSharp as the programming language
Steps:
In the design view of your form, locate the Xtragrid's column that you want to contain the LookUpEdit editor. Left-click that column to choose it and press F4 to open the properties window. In the properties window of your selected column find the ColumnEdit property. You can then assign it a RepositoryItemLookupEdit by clicking the small down arrow icon on the right and choosing New -> LookUpEdit.

You can give it any name you like by modifying the (Name) property below the ColumnEdit property.

In your formName.designer.cs you can check the following codes:
this.repositoryItemLookUpEditName = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
this.your_grid_column_name.ColumnEdit = this.repositoryItemLookUpEditName;
This means that a new lookup edit control (repositoryItemLookUpEditName) has been created and assigned to your grid's column.

The next step is to assign the database table to your lookupedit editor this is done by modifying the DataSource, DisplayMember, and ValueMember property. Return to your formName.cs and enter the following codes in the form load event:
repositoryItemLookUpEditName.DataSource = table_name;
repositoryItemLookUpEditName.DisplayMember = "column_name_in_your_table";
repositoryItemLookUpEditName.ValueMember = "another_column_name_in_your_table (this column usually contains the primary key of your table)";
You can also decide what data will be contained in this lookupedit editor by returning to your grid's column properties window and locating the Columns property. Click the ... button on the right of it to open the 'LookupColumnInfo Collection Editor' window.

In the 'LookupColumnInfo Collection Editor' window you can choose how many columns to be displayed in your lookupedit editor. The two most important properties in this window is the Caption (name of the column displayed to users) and FieldName (the name of the column in your database table)

Build and run your application! In my case users can click my grid's column to see a list of products and then they can choose one.


Note:
  • If the content under 'Members' tab is empty then all the columns in your database table assigned to the DataSource property of the repositoryItemLookUpEditName will be displayed in your lookUpEdit editor when user clicks the column in your grid.

1 comment:

Dorababu said...

Hi I need a small help, how can I get the results from lookup edit based on the search within the lookup, my lookup was binded with name email phone and empid, now when I enter email or name i need to select that row in lookup is it possible

Post a Comment

Blog Archive

About Me

My photo
I am a software developer with roughly 5 years of experience in developing end-to-end solutions in C#, Java, C/C++, PHP and HTML/CSS/Javascript. At the moment, I am joining the Professional Doctorate in Engineering degree program in Software Technology at Eindhoven University of Technology. My areas of particular interest include software design, data structures and algorithms, problem solving, software security, embedded system, machine learning, and data science.