私は2つのフォームを持っています。 form1とform2。 form1にはform2にアクセスするためのボタンがあり、form2にはlistview2といくつかのテキストボックスがあります。私はlistview2に項目を入力することができます。 Form2のOKボタンをクリックすると、form1のlistview1はlistview2のように表示されます。だから、みんな、誰かが私にこれを行う方法を提案することができますか?ありがとうあるフォームから別のフォームにリストビューを渡すにはどうしたらいいですか?
以下は私のコードです。私は皆さんを混乱させないことを願っています。
Form1のコード=>
namespace MainServerPage
{パブリック部分クラスMainServerPage:フォーム {パブリックリストビューLV。
public MainServerPage() { InitializeComponent(); }
private void btnAdd_Click(object sender, EventArgs e)
{
AddItem Add = new AddItem(this); //to open form2
Add.ShowDialog();
}
}
}
フォーム2コード=>
namespace MainServerPage
{パブリック部分クラスAddItemメソッド:フォーム {MainServerPageのcurrentform。 //フォームを別のものに渡すこの方法を学んだが、機能していない。 public AddItem(MainServerPage incomingform) { currentform = incomingform; InitializeComponent();一般的に }
private void btnUpdate_Click(object sender, EventArgs e)
{
ListViewItem item = new ListViewItem(txtCode.Text);
item.SubItems.Add(txtLocation.Text);
item.SubItems.Add(cbxStatus.Text);
item.SubItems.Add(txtWeatherHigh.ToString());
item.SubItems.Add(txtWeatherLow.ToString());
listView2.Items.Add(item); //send to listView2
txtCode.Text = "";
txtLocation.Text = "";
cbxStatus.Text = "";
txtWeatherHigh.Text = "";
txtWeatherLow.Text = "";
cbxZone.Text = "";
}
private void btnOk_Click(object sender, EventArgs e)
{
currentform.LV = load; //I got stuck here...do not know what to do
}
}
}
ありがとうございました...私はそのように作業します。感謝します – EmporerHaki