用字典从子窗体填充组合框 [英] Populating combobox from child form with dictionary

查看:81
本文介绍了用字典从子窗体填充组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天

我在Windows应用程序中创建了两种形式.在我的主窗体上是一个组合框,在我的第二个(子窗体)上是一个按钮.

当在子窗体上单击按钮时,我想用字典填充组合框.

我已经写了字典,该字典要求一个简短的过程.该词典正在运行,并且正在从主要形式中填充.

这是主窗体上的词典代码

Good day

I have created a two forms in my Windows application. On my Main form is a combobox and on my second(child) form is a button.

I want to populate the combobox with a dictionary when the button is clicked on the child form.

I have written the dictionary that is calling a short procedure. The dictionary is working and is populating from the main form.

Here is the dictionary code on the Main Form

public void dctRplStatus()
       {
                Dictionary<string, int> objdic = new Dictionary<string, int>();
                objdic = clsIngadmin.SelectdicReplacementStatus();
                cmbRplStatus.DisplayMember = "Key";
                cmbRplStatus.ValueMember = "Value";
                cmbRplStatus.DataSource = new BindingSource(objdic, null);
                objdic = null;




按钮单击事件上子窗体上的代码




Code on child form on the button click event

frmMain formmain = new frmMain()


formmain.cmbRplStatus = dctRplStatus;



我收到一个错误,无法将类型"void"转换为"System.Windows.Forms.Combobox"

我将dctRplStatus()方法更改为字符串,并尝试返回objdic,但它不起作用.

我做错了什么?

Thanx



I get an error connot convert type ''void'' to ''System.Windows.Forms.Combobox''

I change my dctRplStatus() method to a string and tried to return the objdic but it did not work.

What am I doing wrong?

Thanx

推荐答案

dctRplStatus 的方法签名更改为
Change the method signature of dctRplStatus to
public void dctRplStatus(ComboBox cmbRplStatus)


并替换


and replace

formmain.cmbRplStatus = dctRplStatus;




with

dctRplStatus(formmain.cmbRplStatus);


确保formmain.cmbRplStatus具有public 访问权限.


ensure that formmain.cmbRplStatus has public access.


这篇关于用字典从子窗体填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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