简体   繁体   English

数据绑定COM Interop .Net控件

[英]Data Binding a COM Interop .Net Control

Is it possible to wrap a .NET control up as an ActiveX control to be used in a COM application (VB6 or MS Access VBA) and allow the COM application to set the data binding? 是否可以将.NET控件包装为要在COM应用程序(VB6或MS Access VBA)中使用的ActiveX控件,并允许COM应用程序设置数据绑定? I'd like the control to be a bound control but I do not want to have to write separate data access routines for the control. 我希望该控件成为绑定控件,但我不想为该控件编写单独的数据访问例程。

For example, I'd like to have AutoSuggest functionality in an MS Access comboxbox and so I'm considering using .NET's combobox control together with COM interop. 例如,我希望在MS Access组合框中具有AutoSuggest功能,因此我正在考虑将.NET的组合框控件与COM互操作一起使用。 However, I think my question extends to other .NET controls as well. 但是,我认为我的问题也扩展到其他.NET控件。

Edit1: 编辑1:
Judging by the answers coming in, it appears that many developers are unaware of the fact that you can take .NET controls and turn them into COM Interop ActiveX controls. 从出现的答案来看,似乎很多开发人员都不知道您可以使用.NET控件并将其转换为COM Interop ActiveX控件的事实。 In order to do this you have to download and install a toolkit from Microsoft called "Interop Forms Toolkit 2.1". 为此,您必须从Microsoft下载并安装一个名为“ Interop Forms Toolkit 2.1”的工具包。

What's baffling me though is how you might pass values to these controls such as DAO fields for binding so that the control itself doesn't have to setup a database connection and operate independently from the DAO Bound MS Access form that the control is located on. 不过,令我感到困惑的是,如何将值传递给这些控件(例如DAO字段)进行绑定,以使控件本身不必设置数据库连接并独立于控件所在的DAO Bound MS Access窗体进行操作。

Nope, you can't do that. 不,你不能那样做。 The .NET Languages allow you to build ActiveX DLLs, but that is not what you want. .NET语言允许您构建ActiveX DLL,但这不是您想要的。

No you can't create an ActiveX control in .NET. 不,您不能在.NET中创建ActiveX控件。

You could create a .NET assembly that contained a form with a .NET combobox and expose a COM interop function called SelectValue but you would have to pass all your selection options to the assembly and it return what the user selected, so depending on the cirumstances this may not be feasible, efficient, worth the time, etc. 您可以创建一个包含带有.NET组合框的表单的.NET程序集,并公开一个称为SelectValue的COM互操作函数,但是您必须将所有选择选项传递给该程序集,并返回用户选择的内容,因此取决于具体情况这可能不可行,不高效,不值得花时间等。

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

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