I have a relative question of passing the value from one button to another form.
I have the following code
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
string cod_evento = dataGridView1.CurrentRow.Cells[1].Value.ToString();
codigo_evento = cod_evento;
string sql = " select * from eventos where cod_evento = " + cod_evento + " ";
flowLayoutPanel1.Refresh();
MySqlDataAdapter da = new MySqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.Refresh();
// MessageBox.Show(dt.Rows.Count.ToString());
if (dt.Rows.Count == 0)
{
MessageBox.Show("erro", "erro", MessageBoxButtons.OK);
}
else
{
int y = 20;
int incremento = 30;
int contador = 1;
for (int i = 0; i < dt.Rows.Count; i++)
{
Button b = new Button();
b.Name = i.ToString();
b.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
b.Font = new Font("Verdana", 15);
string sexo = dt.Rows[i]["sexo"].ToString();
string tipo = string.Concat(dt.Rows[i]["nome_area"].ToString()," - ",sexo);
b.Text = string.Concat(sexo.ToString(), tipo.ToString());
b.Click += new EventHandler(this.b_Click);
// vamos carregar para o próximo form
b.Size = new System.Drawing.Size(400, 60);
flowLayoutPanel1.Controls.Add(b);
flowLayoutPanel1.AutoScroll = true;
y = y + incremento;
contador++;
lblCarregando.Text = "";
}
}
}
void b_Click(object sender, EventArgs e)
{
Imprimir imprimir = new Imprimir();
imprimir.sexo = sexo;
imprimir.tipo = tipo;
imprimir.cod_evento = codigo_evento;
// vamos carregar o form com os tipos e quantidades
imprimir.Show();
lblCarregando.Text = "";
}
But it happens in the loop, it shows the values correctly, but when clicking, it sends to print the last result of the loop;