如何填充从另一个表单在一个页面上定义的组合框 [英] How to fill combobox defined on one page from another form
本文介绍了如何填充从另一个表单在一个页面上定义的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我正在使用单件模式(部分)我想从另一个表单填写一个表单上的组合框。我正在使用以下代码
Hi I am using singleton pattern (partially) I want to fill combo-box on one form from another form. I am using following code
for (int i = 0; i < dt.Rows.Count; i++)
{
if ("cmb.Name" == "cmbServer1")
{
GridWindow.Instance.cmbDatabase1.Items.Add(dt.Rows[i]["database_name"]);
}
else
{
GridWindow.Instance.cmbDatabase2.Items.Add(dt.Rows[i]["database_name"]);
}
但是我无法填充组合框,如果你有解决方案,请告诉我为此
提前致谢
Ramesh
But I am not able to fill the combobox,Kindly let me know if you have solution for this
Thanks in advance
Ramesh
推荐答案
你不要告诉我到底出了什么问题,但我还是有一些建议:
这里你比较两个常量字符串,它永远不会是true
:
You don't tell what exactly is going wrong there but I have some suggestions anyway:
Here you compare two constant strings, it will never betrue
:
if ("cmb.Name" == "cmbServer1")
可能你打算这样做:
Probably you meant to do this:
if (cmb.Name == "cmbServer1")
我会建议不要使用其他表格对表格进行硬编码。在一个非常小的项目中,这不是问题,但如果你在项目中添加更多的表格,或者在做大项目时坚持策略,最终会导致维护噩梦。最近有一篇关于这个主题的新文章发表在这里,看一看:一次回答的许多问题 - Windows窗体或WPF Windows之间的协作 [ ^ ]
这篇关于如何填充从另一个表单在一个页面上定义的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文