Data Binding a date from a Datetimepicker

tovia schlesinger 241 Reputation points
2021-10-13T17:41:38.51+00:00

In VB 2019 in a form, I set up that a date is selected from a datetimepicker, and the selected date has to be brought into the textbox named "DateA".
If I use the following code,
DateA.Text = FormatDateTime(Convert.ToDateTime(datetimepicker.Value), DateFormat.ShortDate)
I get an error message "
'Unable to cast object of type 'System.EventArgs' to type

So I used databinding, as follows

Me.DateA.DataBindings.Clear()
DateA.DataBindings.Add("text", datetimepicker.Value, "Value", True, DataSourceUpdateMode.OnValidation, "", "MM/dd/yy").DataSourceUpdateMode = DataSourceUpdateMode.OnValidation

But when I run it, the message is "
'Cannot bind to the property or column "Value" on the DataSource"

So what do I need to write instead of "Value", because when using Value, it generates an error message.

Developer technologies Visual Studio Testing
{count} vote

1 answer

Sort by: Most helpful
  1. tovia schlesinger 241 Reputation points
    2021-10-13T17:52:53.173+00:00

    I change it to
    DateA.DataBindings.Add("text", datetimepicker.Value, "Date", True, DataSourceUpdateMode.OnValidation, "", "MM/dd/yy").DataSourceUpdateMode = DataSourceUpdateMode.OnValidation

    and is fine

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.