3
I have a question regarding passing the value of a 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 turns out that in the loop, it shows right values, but when clicking, it sends to the print the last result of the loop;
Thank you. But when I try to recover her values with the data.count. it comes back zeroed
– tupinikin
The variable you declared globally?
– Laerte
Yes, I have globally declared the variables
– tupinikin