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.

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
329 questions
{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