ListBox in devexpress gridview in c#

懵懂的女人 提交于 2019-12-11 12:41:00

问题


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

回答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.



来源:https://stackoverflow.com/questions/38606931/listbox-in-devexpress-gridview-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!