combobox没有显示选项

yy_9117 2019-04-13 05:05:42
我在vsto里生成了一个任务窗格,窗格里有个combobox控件,不管在哪初始化combobox的items都没有下拉框也没有选项


初始化的时候代码如下

Microsoft.Office.Tools.CustomTaskPane ctp1;
UserControl1 uc1;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
uc1 = new UserControl1();
ctp1 = Globals.ThisAddIn.CustomTaskPanes.Add(uc1, "初始化密钥");
ctp1.Visible = true;

//MessageBox.Show("加载成功!");

}
这是一个ThisAddIn.cs里的

下面是UserControl1.cs里的
public partial class UserControl1 : UserControl
{

public UserControl1()
{

InitializeComponent();
}
private void UserControl1_load(object sender, EventArgs e)
{
this.comboBox1.Items.Add("默认密钥");
this.comboBox1.Items.Add("自定义密钥");

this.comboBox1.SelectedIndex = 0;
}


...全文
584 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
牧歌ing 2019-04-24
  • 打赏
  • 举报
回复
引用 4 楼 yy_9117 的回复:
[quote=引用 3 楼 weixin_41923258 的回复:]
private void UserControl1_load(object sender, EventArgs e)
{
this.comboBox1.Items.Add("默认密钥");
this.comboBox1.Items.Add("自定义密钥");
MessageBox.Show("下拉列表数量:“+this.comboBox1.Items.Count);
//加上这句,并设定中断,运行时调试看看,是否已加上内容
this.comboBox1.SelectedIndex = 0;
}



并没有弹出任何消息![/quote]


你的控件绑定的load事件是这个吗
yy_9117 2019-04-14
  • 打赏
  • 举报
回复
引用 3 楼 weixin_41923258 的回复:
private void UserControl1_load(object sender, EventArgs e) { this.comboBox1.Items.Add("默认密钥"); this.comboBox1.Items.Add("自定义密钥"); MessageBox.Show("下拉列表数量:“+this.comboBox1.Items.Count); //加上这句,并设定中断,运行时调试看看,是否已加上内容 this.comboBox1.SelectedIndex = 0; }
并没有弹出任何消息!
夏小巫 2019-04-14
  • 打赏
  • 举报
回复
private void UserControl1_load(object sender, EventArgs e)
{
this.comboBox1.Items.Add("默认密钥");
this.comboBox1.Items.Add("自定义密钥");
MessageBox.Show("下拉列表数量:“+this.comboBox1.Items.Count);
//加上这句,并设定中断,运行时调试看看,是否已加上内容
this.comboBox1.SelectedIndex = 0;
}
秋的红果实 2019-04-13
  • 打赏
  • 举报
回复
在UserControl1.designer.cs里面,将comboBox1的private改为public
yy_9117 2019-04-13
  • 打赏
  • 举报
回复
已经把ComboBox的属性DropDownStyle为DropDownList了

111,075

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧