简体   繁体   English

在Excel列表对象中使用数据绑定时如何创建查找列

[英]How to create a lookup column when using data binding with Excel listobject

I am working on a VSTO project using excel 2010 and visual studio 2010. 我正在使用excel 2010和visual studio 2010进行VSTO项目。

I have successfully binded an excel listobject to a BindingList collection and I am trying to modify the listobject so that certain columns contains look up drop downs. 我已经成功地将excel列表对象绑定到BindingList集合,并且试图修改列表对象,以便某些列包含查找下拉列表。 Furthermore, I am trying to configure the particular column that it can translate the look up text to the look up value (integer). 此外,我正在尝试配置特定的列,使其可以将查找文本转换为查找值(整数)。

I know the build in excel SharePoint list can achieve this. 我知道excel SharePoint列表中的构建可以实现此目的。 Question is, can we do it? 问题是,我们可以做到吗?

thanks 谢谢

I resolved this issue by creating a special PropertyDescriptor for the lookup fields. 我通过为查找字段创建特殊的PropertyDescriptor解决了此问题。 The property descriptor will do a reversed lookup when the SetValue method is invoked by the listobject. 当ListObject调用SetValue方法时,属性描述符将进行反向查找。 It will do a forward lookup when the GetValue is invoked. 调用GetValue时,它将进行正向查找。

This way, as far as the object model is concerned, it is receiving the correct values and the excel is receiving the correct text. 这样,就对象模型而言,它接收正确的值,而excel接收正确的文本。 I can then use the excel validation to create drop downs on the UI. 然后,我可以使用excel验证在UI上创建下拉列表。

The catch is that the lookup text needs to be unique. 问题是查找文本必须唯一。 Otherwise, reversed lookup is impossible. 否则,反向查找是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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