C#excel addin - 访问控件 [英] C# excel addin - Accessing Controls

查看:165
本文介绍了C#excel addin - 访问控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#编写一个excel 2010的插件。我有一个现有的工作表,其中有一些控件,即ComboBox。我正在尝试编写一些代码,它将在组合框的文本属性中放置一些值,但是我很难得到控件的访问权限。

I am working on an addin for excel 2010 using C#. I have an existing worksheet that has some controls in it, namely a ComboBox. I am trying to write some code that will place a certain value in the combo box's text property, but I am having a hard time getting access to the control to do so.

组合框命名为ComboBox1,但如果我尝试像... ...

The combo box is named 'ComboBox1' but if I try something like...

var combo = Controls["ComboBox1"];

我得到一个ArgumentOutOfRangeException。

I get an ArgumentOutOfRangeException.

探索找出我应该做的事情的方法也没有真正提供有用的信息。例如,如果要写;

Exploratory approaches to finding out what I am supposed to be doing aren't really providing useful information either. For example, if were to write;

MessageBox.Show(Controls[0].GetType())

显示的消息是NamedRangeImpl,根本看起来不是一个控件。所以我的问题是,如何从我的代码访问我的工作表上的控件?

The displayed message is 'NamedRangeImpl' which doesn't seem like a control at all. So my question is, how do I get access to the controls that are on my worksheet from my code?

推荐答案

不完全确定的问题,但我已经做了插件的字,如果它的窗口形式这应该工作很好。

I'm not exactly sure about the problem but I've made addins for word and if its like windows forms this should work nicely.

foreach (Control c in Controls) 
   if (c.Name == "comboBox1") {
      ComboBox box = (ComboBox)c;
      box.Items.Add("Thing added");
   }

这篇关于C#excel addin - 访问控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆