列表框在devexpress gridview在c# [英] ListBox in devexpress gridview in c#
问题描述
我有一个gridview,你可以在这里看到:
I have a gridview as you can see here:
如您所见,我读到 materialrequestcontractorId
中的数据,我有一个列表框,该列表框从数据库读取其值,如下所示:
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);
}
但问题是我需要向我的用户显示我的 MaterialRequestContractor
不是它的 id
,该id应该是我的名字的值,并保存在数据库中,但在devexpress中我可以'请将此值和文本分配给列表框?
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为WinForms提供了几个查找编辑器(LookUpEdit,GridLookUpEdit,SearchLookUpEdit)支持这种场景开箱即用。想法是LookUp编辑器有自己的数据源。当它在网格中显示时,它会从其数据源中的网格单元格(由LookUpEdit.Properties.ValueMember属性确定的关键列)中找到一个值,并显示从选择为DisplayMember的字段中的值。
所以如果你放置一个具有MaterialRequestContractor和MaterialRequestContractorId字段的表,并且正确选择DisplayMember和ValueMember,则DevExpress网格应该像你所描述的那样工作。
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.
这篇关于列表框在devexpress gridview在c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!