Programmatically change the date displayed in a "Datepicker" control?

Asked

Viewed 65 times

1

I’m trying to display data from a table field MySQL in a control DatePicker. The code is as follows::

if (dataGridProdutos.SelectedIndex != -1)
{
    DateTime selectedDate;
    DataRowView selectedRecord = (DataRowView)dataGridProdutos.SelectedItem;
    selectedDate = (DateTime)selectedRecord.Row.ItemArray[2];
    dataNascTextBox.Text = selectedDate.Date.ToString("yyyy/MM/dd");
    dataNascDatePicker ????
    ...
}

How can I complete this line concerning dataNascDatePicker?

  • This dataNascDatePicker.Value=selectedDate.Date; does not work? see link https://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.value

  • I had already tried and not ... unless I’m missing some detail!

  • What happens when Voce does this: dataNascDatePicker.Value=selectedDate.Date; ?

1 answer

1

I resolved so:

DateTime selectedDate;
DataRowView selectedRecord = (DataRowView)dataGridProdutos.SelectedItem;
...
selectedDate = (DateTime)selectedRecord.Row.ItemArray[2];
dataNascDatePicker.SelectedDate = selectedDate;
...

Browser other questions tagged

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