Here are all my classes.が</p> <p>CustomerFrame =テキストボックス</p> <p>私は私のプログラムをコンパイルし、
のMainForm =リストビューをリストビューにアイテムを挿入することはできません、私のMainForm
は空のリストビューで表示され、私は追加ボタンを押したときアイテムを挿入すると、CustomerFrame
クラスが表示されます。テキストボックスに書き込みして[OK]をクリックすると、何の項目は私のリストビュー(MainForm
)に挿入されません。どうして?
いくつかのコード:
MainFormを
using(var customerframe = new CustomerFrame())
{
if (customerframe.DialogResult == DialogResult.OK)
{
CustomerFiles.Contact contact = customerframe.GetContact();
CustomerFiles.Address address = customerframe.GetAddress();
CustomerFiles.Phone phone = customerframe.GetPhone();
CustomerFiles.Email email = customerframe.GetEmail();
//Items in my listview
listviewitem = new ListViewItem();
listviewitem.SubItems.Add(contact.FirstName);
listviewitem.SubItems.Add(contact.LastName);
listviewitem.SubItems.Add(phone.Home);
listviewitem.SubItems.Add(phone.Mobile);
listviewitem.SubItems.Add(address.Country);
listviewitem.SubItems.Add(address.ZipCode);
listviewitem.SubItems.Add(address.City);
listviewitem.SubItems.Add(address.Street);
listviewitem.SubItems.Add(email.Personal);
this.listView1.Items.Add(listviewitem);
}
}
MainFormを
private void addToolStripMenuItem_Click_1(object sender, EventArgs e)
{
customerframe.Show();
CustomerManager cm = new CustomerManager();
}
CustomerFrame
ところで、私はCustomerFrame
フォームがMainForm
前に現れる(私はしたくないもの)と、それは一度だけアイテムを挿入しますが、作る
if (customerframe.ShowDialog() == DialogResult.OK)
これを使用しています。
スコープの問題のように私に見えます。ステップバイステップのデバッグを行い、メソッド/クラスの追加後にリストビューの内容を確認します。 – Zenwalker
私はこれを何度も繰り返してきましたが、問題は "(var customerframe = new CustomerFrame()) { if(customerframe.DialogResult == DialogResult.OK) {"この行またはこの行 " this.listView1.Items.Add(listviewitem); " – user1067973