How to return value to a Datetimepicker? C#

Asked

Viewed 432 times

2

I’m wanting to return data from a DataGridView for a DataTimePicker so that I can change this data and save it again, but I’m having a hard time doing so because the DataTimePicker does not accept value type.

private void btnAlterar_Click(object sender, EventArgs e)
{
    FrmCadCliente frmcadcliente = new FrmCadCliente();
    frmcadcliente.Show();

    frmcadcliente.txtID.Text = pacientes_TCCDataGridView.SelectedRows[0].Cells[0].Value.ToString();
    frmcadcliente.txtNome.Text = pacientes_TCCDataGridView.SelectedRows[0].Cells[1].Value.ToString();
    frmcadcliente.txtCPF.Text = pacientes_TCCDataGridView.SelectedRows[0].Cells[2].Value.ToString();
    frmcadcliente.txtRG.Text = pacientes_TCCDataGridView.SelectedRows[0].Cells[3].Value.ToString();
    frmcadcliente.cbxSexo.Text = pacientes_TCCDataGridView.SelectedRows[0].Cells[4].Value.ToString();
    frmcadcliente.dtpData.Text = pacientes_TCCDataGridView.SelectedRows[0].Cells[5].Value.ToString();
}

The error happens on this last line in Value

1 answer

3


You can try to do the following:

frmcadcliente.dtpData.Value = Convert.ToDateTime(pacientes_TCCDataGridView.SelectedRows[0].Cells[5].Value.ToString());
  • WOW! Thank you so much for answering, look worked yes!! I just changed frmcadcliente.dtpData.Text for frmcadcliente.dtpData.Value and worked perfectly thank you very much!

  • @Gabrielarruda, Dispo!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.