hi, I got 2 forms
form1 is got 1 button 1 datagridview what I want to do when I click button open the form2 as show dialog
here is the codes for form2
private void btnImport_Click(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
frm2.ShowDialog();
}
after form2 is opened I got 2 button 1 listbox in the form
what I want to do when I click the first button import my email address into listbox and when I click the second button I want to do move listbox1 items to form1 datagridview but I'm getting not seeing my email address in datagridview
here is the codes
private void btnImport_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = false;
DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
System.IO.StreamReader sr = new System.IO.StreamReader(@ofd.FileName);
string line;
while ((line = sr.ReadLine()) != null)
{
listBox1.Items.Add(line);
}
}
}
private void btnMove_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
foreach (var item in listBox1.Items)
{
int idx = frm1.dataGridView1.Rows.Add();
frm1.dataGridView1.Rows[idx].Cells["Email"].Value = item;
this.Close();
}
}
when I use the all codes at 1 form its work perfectly but when I want to seperate to 2 forms I'm not getting anything
how can I move listbox items to datagridview from form2 to from1
What I have tried:
Form1 frm1 = new Form1();
foreach (var item in listBox1.Items)
{
int idx = frm1.dataGridView1.Rows.Add();
frm1.dataGridView1.Rows[idx].Cells["Email"].Value = item;
frm1.Show();
this.Close();
}
this work but its opening another form1 so I don't want this I want to get back same form
Form1 frm1 = new Form1();
foreach (var item in listBox1.Items)
{
int idx = frm1.dataGridView1.Rows.Add();
frm1.dataGridView1.Rows[idx].Cells["Email"].Value = item;
frm1.SendToBack();
this.Close();
}
this sending back to me same form but I'm not seeing the listbox items in datagridview
private void btnMove_Click(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
foreach (var item in listBox1.Items)
{
int idx = frm1.dataGridView1.Rows.Add();
frm1.dataGridView1.Rows[idx].Cells["Email"].Value = item;
this.Close();
}
}
also this sending back to me same form but I'm not seeing the listbox items in datagridview