如何在另一种形式的列表框中获取项目 [英] How Do I Get Items In A Listbox That Is In Another Form

查看:66
本文介绍了如何在另一种形式的列表框中获取项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我的项目Form1和Form2中有2个表格



我有在Form1中初始化时,在Form2中的列表框中获取项目。



这是Form1中的代码:



Hello all.

I have 2 Form in my project Form1 and Form2

I have to get items in a Listbox in Form2 when initializing in Form1.

Here is the code in Form1:

private void OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new XmppClientConnection.RosterHandler(OnRosterItem), new object[] { this, item });
                return;
            }
            if (item.Subscription == SubscriptionType.both)
            {
                for (int i = 0; i < listBox1.Items.Count; i++)
                {
                    if (item.Jid.ToString() == listBox1.Items[i].ToString())
                    {
                        listBox1.Items.Remove(item.Jid);
                    }
                }
                listBox1.Items.Add(item.Jid.ToString());
            }
        }







此Listbox1在Form2中如何获取那里的项目。



谢谢




This Listbox1 is in Form2 how to get the items there.

Thank you

推荐答案

也许这个代码项目文章可以帮助你。



在表单之间传递数据



JAFC
Maybe this code project article can help you.

Passing Data Between Forms

JAFC


如果form2作为弹出窗口打开,那么你可以直接评估form1.listbox1.selecteditem并循环遍历它填充form2列表框。
if form2 is open as a pop up then u can direct assess form1.listbox1.selecteditem and loop through it and populate the form2 listbox.


这篇关于如何在另一种形式的列表框中获取项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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