1
I am passing a completed DTO object to an editing form, through the event click on a Change button.
In this edition form, I want all fields to be filled out as soon as it is opened, but the fields that are combo box are not being filled in the others yes.
private void btnAlterar_Click(object sender, EventArgs e)
{
dto.Id = (int)DgvCadListReceita.CurrentRow.Cells[0].Value;
dto.Descricao = DgvCadListReceita.CurrentRow.Cells[1].Value.ToString();
dto.Valor = Convert.ToDouble(DgvCadListReceita.CurrentRow.Cells[2].Value);
dto.CategoriaReceita = (int)DgvCadListReceita.CurrentRow.Cells[3].Value;
dto.DescCategoria = DgvCadListReceita.CurrentRow.Cells[4].Value.ToString();
dto.Conta = (int)DgvCadListReceita.CurrentRow.Cells[5].Value;
dto.DescConta = DgvCadListReceita.CurrentRow.Cells[6].Value.ToString();
dto.DataVencimento = (DateTime)DgvCadListReceita.CurrentRow.Cells[7].Value;
dto.Observacao = DgvCadListReceita.CurrentRow.Cells[8].Value.ToString();
FrmCadReceita frm = new FrmCadReceita(dto);
frm.ShowDialog();
CarregarGrid();
}
On the completed DTO form
public FrmCadReceita(ReceitaDTO dto)
{
InitializeComponent();
txtDescricaoReceita.Text = dto.Descricao;
txtValorReceita.Text = Convert.ToString(dto.Valor);
cboCategoriaReceita.Text = dto.DescCategoria.ToString();
cboConta.Text = dto.DescConta;
dtpDataVencimentoReceita.Text = dto.DataVencimento.ToString();
txtObservacaoReceita.Text = dto.Observacao;
}
How do I get the combobox to start with the value of the description in the DTO object? in this case I am passing the string type value, but I have the idCategory DTO filled in as well