Convert a DataGridView Cell Value into a DateTime

krieg

I've been searching for some time now for this answer:

I've got a datagridview that has a cell with dates, and I need to make the value in that cell a DateTime value that can go with my DateTimePicker

So far I've done this, but it's not working, it gives me a System.FormatException (apparently it can't recognize the string as a DateTime, which sounds about right)

This is the code in question:

int index = ReservationDataGridView.SelectedRows[0].Index;
string date = ReservationDataGridView[0, 1].Value.ToString();
DateTime test = DateTime.ParseExact(date, "dd/MM/yyyy - hh:mm tt", System.Globalization.CultureInfo.InvariantCulture);

MessageBox.Show(test.ToString()

This is how my DateTimePicker is formatted:

ReservationDateTimePicker.Format = DateTimePickerFormat.Custom;
ReservationDateTimePicker.CustomFormat = "dd/MM/yyyy - hh:mm tt";

And this is how the dates look in the DataGridView:

DataGridView

Any ideas on how I can convert the DataGridView's Date value into a DateTime that will fit into a DateTimePicker with that formaT?

Mitch Wheat

Rather than take the string representation of the DateTime value from the DataGridview cell, instead retrieve the actual DateTime value from the DataDridview's datasource.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to show the complete DateTime value in a Datagridview cell when it is exactly midnight?

From Dev

DataGridView Cell Value Changing

From Dev

DataGridView Cell Value Changing

From Dev

Hiding a value in a datagridview cell

From Dev

Change DataGridView Cell Value Programmatically

From Dev

change cell in datagridview to empty value

From Dev

How to change value of one cell onchange of other cell value in DataGridview

From Dev

Convert value to datetime

From Dev

Convert the datetime value to floor

From Dev

Convert the datetime value to floor

From Dev

DataGridView update Cell Value while typing

From Dev

Change datagridview cell value in edit mode

From Dev

Restoring Previous cell value in c# datagridview

From Dev

How to get image value of Datagridview Image Cell

From Dev

C# retrieve cell value from datagridview

From Dev

How to get a value of a cell in datagridview devexpress

From Dev

Get DataGridView cell value in nested For Loops

From Dev

Pass empty cell value from datagridview

From Dev

Failed to convert parameter value -- Updating changes to a DataGridView

From Dev

Convert an integer value to datetime in sqldf

From Dev

Convert Cookie string in DateTime value

From Dev

How to convert ticker value to datetime?

From Dev

Datagrid change a cell value if it's default(dateTime)

From Dev

Datagrid: Post String value into the Cell of a DateTime column

From Dev

Issue in getting the value from datagridview cell to put into decimal

From Dev

DataGridView Event to Catch When Cell Value Has Been Changed by User

From Dev

How do I track the old value in a datagridview cell?

From Dev

How to get cell value from DataGridView in VB.Net?

From Dev

DataGridView Cell value not available for validation when inserting a new row

Related Related

  1. 1

    How to show the complete DateTime value in a Datagridview cell when it is exactly midnight?

  2. 2

    DataGridView Cell Value Changing

  3. 3

    DataGridView Cell Value Changing

  4. 4

    Hiding a value in a datagridview cell

  5. 5

    Change DataGridView Cell Value Programmatically

  6. 6

    change cell in datagridview to empty value

  7. 7

    How to change value of one cell onchange of other cell value in DataGridview

  8. 8

    Convert value to datetime

  9. 9

    Convert the datetime value to floor

  10. 10

    Convert the datetime value to floor

  11. 11

    DataGridView update Cell Value while typing

  12. 12

    Change datagridview cell value in edit mode

  13. 13

    Restoring Previous cell value in c# datagridview

  14. 14

    How to get image value of Datagridview Image Cell

  15. 15

    C# retrieve cell value from datagridview

  16. 16

    How to get a value of a cell in datagridview devexpress

  17. 17

    Get DataGridView cell value in nested For Loops

  18. 18

    Pass empty cell value from datagridview

  19. 19

    Failed to convert parameter value -- Updating changes to a DataGridView

  20. 20

    Convert an integer value to datetime in sqldf

  21. 21

    Convert Cookie string in DateTime value

  22. 22

    How to convert ticker value to datetime?

  23. 23

    Datagrid change a cell value if it's default(dateTime)

  24. 24

    Datagrid: Post String value into the Cell of a DateTime column

  25. 25

    Issue in getting the value from datagridview cell to put into decimal

  26. 26

    DataGridView Event to Catch When Cell Value Has Been Changed by User

  27. 27

    How do I track the old value in a datagridview cell?

  28. 28

    How to get cell value from DataGridView in VB.Net?

  29. 29

    DataGridView Cell value not available for validation when inserting a new row

HotTag

Archive