vendredi 3 juin 2016

C# if statement skipped even if condition is met

im writing a basic program on c# for school and im having trouble with an if statement where the condition gets met but the code gets skipped as if the condition wasn't met.

//this runs when i select a cell on the dataGridView
 private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
    {

        string estado = "";
        if (e.RowIndex >= 0)
        {
            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            id_lbl.Text = row.Cells[0].Value.ToString();
            nombre_lbl.Text = row.Cells[1].Value.ToString();
            apellido_lbl.Text = row.Cells[2].Value.ToString();
            estado = row.Cells[7].Value.ToString();
        }

        id_lbl.Visible = true;
        nombre_lbl.Visible = true;
        apellido_lbl.Visible = true;

        if(estado == "Activo")
        {
            baja_btn.Enabled = true;
        }
        else if (estado == "NoActivo")
        {
            alta_btn.Enabled = true;
        }
        else
        {
            MessageBox.Show(estado);
        }
    }

code runs but if statement jumps directly to else code and mesage box displays Activo, how ever, baja_btn.Enabled = true; does not run. same is true if i select row with NoActivo.. if jumps straight to else...

thank you in advance

Aucun commentaire:

Enregistrer un commentaire