让我们说我有以下两个类
public class OtherClass
{
public string OtherName{ get; set; }
}
public class MyClass
{
public string TheName { get; set; }
public int TheAge { get; set; }
}
假设我将XtraGrid
绑定到Object
数据源(MyClass
)
现在,我的方案是,当我点击来自TheName
对象列表的Editor button
OtherName
的{{1}}时,我想填充第一列(OtherClass
) List<OtherClass>
)
然后最终将整行转回MyClass
对象
可能吗?
答案 0 :(得分:0)
也许是这样的:
List<MyClass> mylist = new List<MyClass>();
mylist.Add(new MyClass() { TheName = "Kirk", TheAge = 56 });
mylist.Add(new MyClass() { TheName = "Spock", TheAge = 403 });
mygrid.DataSource = mylist;
mygrid.MainView.PopulateColumns();
List<OtherClass> all_names = new List<OtherClass>();
在此处添加现有名称:
foreach (var item in mylist)
all_names.Add( new OtherClass() { OtherName = item.TheName } );
继续使用其他名称:
all_names.Add(new OtherClass() { OtherName = "Watson" });
all_names.Add(new OtherClass() { OtherName = "Sherlock" });
通过设计师
创建repositoryItemLookUpEdit1 repositoryItemLookUpEdit1.DataSource = all_names;
repositoryItemLookUpEdit1.DisplayMember = "OtherName";
repositoryItemLookUpEdit1.ValueMember = "OtherName";
((DevExpress.XtraGrid.Views.Base.ColumnView)mygrid.MainView).Columns[0].ColumnEdit = repositoryItemLookUpEdit1;
你的数据应该没问题