简体   繁体   中英

ListBox in devexpress gridview in c#

I have a gridview as you can see here:

在此输入图像描述

As you can see i read the data in materialrequestcontractorId i have a listbox that this listbox reads its value from the database as you can see here:

List<MaterialRequestContractor> lstMRC = _materialRequestContractorRepository.Get().ToList();
            foreach (MaterialRequestContractor VARIABLE in lstMRC)
            {
                LstMaterialRequestContractorId.Items.Add(VARIABLE.Id);
            }

But the problem is i need to show my user the name of my MaterialRequestContractor not its id ,the id should be the value of my name and be saved in database .but in devexpress i can't assign this value and text to list box?

I have a record in my MaterialRequestContractor database with id=1

DevExpress provides several lookup editors for WinForms (LookUpEdit, GridLookUpEdit, SearchLookUpEdit) which support such scenario out-of-the-box. The idea is that LookUp editor has its own data source. When it is shown in the grid, it finds a value with from the grid cell in its data source (the key column determined by the LookUpEdit.Properties.ValueMember property) and shows the value from a field that selected as DisplayMember. So if you put a table that has MaterialRequestContractor and MaterialRequestContractorId fields, and properly select DisplayMember and ValueMember, the DevExpress grid should work just like you described.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM