I've been messing with C # lately and am having difficulties.
I want to get information from multiple selected rows in DataGridView
, and, depending on the number of rows, pass this information to forms that will be displayed, as long as two rows are selected, two rows are created (each with line that was selected), and so on. The problem is that if I select a row, that's fine, however, when I select more rows, it always opens the forms with the last line information that was selected.
How do you select the right information for each line?
Follow 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;
}
}