将项目添加到组合框 [英] adding items to combobox

查看:51
本文介绍了将项目添加到组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向组合框添加一些项目,如msdn网站上显示的那样,但它抛出了空引用异常

I am trying to add some items to combobox, like its showed on msdn site, but it throws me an null reference exception

 comboBox1.Items.Add("test");

我尝试更改它

ComboBox combobox1 = new ComboBox();
object test = new object();
test= "test";
comboBox1.Items.Add(test);

但是它也没有用
你能告诉我,问题出在哪里?
谢谢

But it didnt works too Can you tell me, where is the problem? Thanks

编辑:
解决:
问题是,我在打电话

SOLVED : problem was, that I was calling

InitializeComponent();

在此代码之后,而不是之前,现在它像我之前希望的那样工作:)

after this code, not before, now it works as I would like before :)

推荐答案

替换为

ComboBox combobox1 = new ComboBox();
object test = new object();
test= "test";
combobox1.Items = new ArrayList();
combobox1.Items.Add(test);

comboxbox1 comboBox1 不相同

这篇关于将项目添加到组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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