0
I need to show off "Active" or "Inactive" in the column Situation of Datagridview, how to do ?
This "Situation" Column is of the Boolean type:
This is the code where I fill out 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);
}
}
You can change the column type to text and the data type (returned in
ConvenioNegocio.ListarConvenioMedico
) forstring
.– Jéf Bueno
Incidentally, capturing an exception just to launch a new one with the same message doesn’t make any sense. This way, you lose the origin of the problem and still force Runtime to make the unnecessary release of an exception.
– Jéf Bueno
an option is to create a property in the model to represent it:
public string StatusNome { {get{ return this.Status ? "Ativo" : "Inativo"; } }
– Rovann Linhalis
It is a much better option, by the way. Just a note: it could be written like this:
public string StatusNome => Status ? "Ativo" : "Inativo"
– Jéf Bueno
@LINQ thanks for the remark I changed my code and left only throw;, catch{ throw; }.
– hard123
can even take out the Try catch... the exception will propagate in the same way...
– Rovann Linhalis