How to replace the CheckBox with a String

0

I need to display "Active" or "Idle" in the Status column of the DataGridView , how do?

This"Situation" column is Boolean type:

This is the Code where I populate the DataGridView :

private void PreencherDataGridView()
        {
            try
            {
                ConvenioModel convenio = new ConvenioModel();
                convenio.STATUS = rdbFiltroAtivo.Checked;
                dgvConvenio.DataSource = ConvenioNegocio.ListarConvenioMedico(convenio);

                dgvConvenio.Columns["ID_CONVENIO_MEDICO"].Visible = false;                    
                dgvConvenio.Columns["CNPJ"].Width = 80;
                dgvConvenio.Columns["RAZAO_SOCIAL"].Width = 150;
                dgvConvenio.Columns["NM_FANTASIA"].Width = 150;
                dgvConvenio.Columns["DT_CADASTRO"].Width = 50;
                dgvConvenio.Columns["DT_ULT_ATUALIZACAO"].Width = 50;
                dgvConvenio.Columns["STATUS"].Width = 30;

                dgvConvenio.Columns["RAZAO_SOCIAL"].HeaderText = "RAZÃO SOCIAL";
                dgvConvenio.Columns["NM_FANTASIA"].HeaderText = "NOME FANTASIA";
                dgvConvenio.Columns["DT_CADASTRO"].HeaderText = "DT CADASTRO";
                dgvConvenio.Columns["DT_ULT_ATUALIZACAO"].HeaderText = "ATUALIZAÇÃO EM";
                dgvConvenio.Columns["STATUS"].HeaderText = "SITUAÇÃO";

                dgvConvenio.Columns["CNPJ"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dgvConvenio.Columns["DT_CADASTRO"].DefaultCellStyle.Format = "dd/MM/yyyy";
                dgvConvenio.Columns["DT_ULT_ATUALIZACAO"].DefaultCellStyle.Format = "dd/MM/yyyy";
                dgvConvenio.Columns["CNPJ"].DefaultCellStyle.Format = "00.000.000/0000-00";


                dgvConvenio.ScrollBars = ScrollBars.Both;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    
asked by anonymous 15.06.2018 / 23:10

1 answer

1

I'll assume your object loaded in DataGridView is ConvenioNegocio . Then, you create a read-only property that will display the value as string :

public class ConvenioNegocio
{
    //...outras propriedades
    public bool Status {get;set;}
    public string Situacao => Status ? "Ativo" : "Inativo;
}

You will now have one more column of the DataGridView to represent the Situacao property, just hide the STATUS :

 dgvConvenio.Columns["STATUS"].Visible = false;

 dgvConvenio.Columns["SITUACAO"].HeaderText = "Situação";
  

Ps. I do not know how you're generating the columns, so it's just an example.

    
16.06.2018 / 04:20