3
I’ve been messing with C# lately and I’m having a hard time.
I want to get information from several selected lines on DataGridView
, and, depending on the number of lines, pass this information to forms that will be displayed, provided that, if two lines are selected, two forms will be created (each with the information of each row that was selected), and so on. The problem is that if I select a line, everything is fine, but when I select more lines, it always opens the forms with the information of the last line that was selected.
How to select the right information for each row?
Follows the Code:
private void button1_Click_1(object sender, EventArgs e)
{
string email, nome;
foreach (DataGridViewRow row in dgvEmpresas.SelectedRows)
{
email = dgvEmpresas.CurrentRow.Cells[2].Value.ToString();
nome = dgvEmpresas.CurrentRow.Cells[1].Value.ToString();
trat = dgvEmpresas.CurrentRow.Cells[3].Value.ToString();
frmEmail f = new frmEmail();
f.MdiParent = this.MdiParent;
f.Show();
f.txtEnviarPara.Text = email;
f.lblTratamento.Text = trat;
f.cboEmpresas1.Text = nome;
}
}
It worked! Thank you very much, Max!
– Leonardo
Oops, I’m happy. Mark as answered ae. Abs and good programs!!
– Max Dolabella