ListBox in devexpress gridview in c#

2019-07-25 10:36发布

I have a gridview as you can see here:

enter image description 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

1条回答
走好不送
2楼-- · 2019-07-25 11:20

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.

查看更多
登录 后发表回答