[英]Moving data from listbox in one form to a listbox in another (Visual C#)
I'm a total novice at C# (have been learning Java til now) and this is my first time posting! 我是C#的新手(至今一直在学习Java直到现在),这是我第一次发布! I've had a look around the forum but can't find what I need. 我在论坛上看了一眼,但找不到我需要的东西。
I'm trying to move details of a string from a list box in one form to a list box in another form - it's supposed to be an email client. 我正在尝试将字符串的详细信息从一种形式的列表框移动到另一种形式的列表框-它应该是电子邮件客户端。
The original data is taken in by a stream reader and split into name and email. 原始数据由流阅读器获取,并分为名称和电子邮件。
Here's the code section for the form that has the data (frmAddressBook): 这是具有数据(frmAddressBook)的表单的代码部分:
public void btnOK_Click(object sender, EventArgs e)
{
if (tmpLine.StartsWith(lstAddresses.SelectedItem.ToString()))
{
//Split the line.
namesEmailAddresses = tmpLine.Split(',');
lstTest.Items.Add(namesEmailAddresses[0] + ", " + namesEmailAddresses[1]);
frmWorldEmail frmWE = new frmWorldEmail();
frmWE.names = namesEmailAddresses[0];
frmWE.emails = namesEmailAddresses[1];
frmWE.Show();
}//if
}
And the code section of the form I'm trying to get the data into (frmWorldEmail): 我试图将数据导入(frmWorldEmail)的表单的代码部分:
public partial class frmWorldEmail : Form
{
public frmWorldEmail()
{
InitializeComponent();
}
public string names
{
get {
names = this.names;
return names;
}
set { }
}
public string emails
{
get {
emails = this.emails;
return emails;
}
set { }
}
public void lstNameTo_SelectedIndexChanged(object sender, EventArgs e)
{
lstNameTo.Items.Add(names);
lstNameTo.Show();
}
public void lstEmailTo_SelectedIndexChanged(object sender, EventArgs e)
{
lstEmailTo.Items.Add(emails);
lstEmailTo.Show();
}
}
I'd really appreciate any help. 我真的很感谢您的帮助。
Thanks. 谢谢。
Change your form to this. 将您的表格更改为此。 I don't get it what you're adding the items in the selected index changed event 我不明白您在所选索引更改事件中添加项目的原因
public partial class frmWorldEmail : Form
{
public frmWorldEmail(string names, string emails)
{
InitializeComponent();
lstNameTo.Items.Add(names);
lstEmailTo.Items.Add(emails);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.