none
The DateTimePicker1 value changes RRS feed

  • Question

  • I want to change the value of the DateTimePicker1from one of the Data Grid View cells

    i used the following code but nothing appeare
     
    Me.dtDate.Value = DataGridView1.SelectedRows(0).Cells(11).Value
    When using this code, the previous date shows saving from the same tool without problems
     MsgBox(DataGridView1.SelectedRows(0).Cells(11).Value)



    Tuesday, December 12, 2017 8:59 AM

Answers

  • Hi,

    I suppose value of DataGridView1.SelectedRows(0).Cells(11) is not DateTime type.  Check if it is DateTime type.
    Dim dt As DateTime
    Dim str As String = DataGridView1.SelectedRows(0).Cells(11).value
    If DateTime.TryParse(str, dt) Then
    	Console.WriteLine("{0} can be parsed into DateTime{1}", str, dt)
    Else
    	Console.WriteLine("{0} cannot be parsed into DateTim", str)
    End If
    Regards,

    Ashidacchi

    • Marked as answer by ahmeddc Tuesday, December 12, 2017 3:04 PM
    Tuesday, December 12, 2017 9:47 AM
  • Me.dtDate.Value = Cdate(DataGridView1.SelectedRows(0).Cells(11).Value)

    Success
    Cor

    • Proposed as answer by Ashidacchi Tuesday, December 12, 2017 10:47 AM
    • Marked as answer by ahmeddc Tuesday, December 12, 2017 3:04 PM
    Tuesday, December 12, 2017 10:36 AM

All replies

  • Hi,

    I suppose value of DataGridView1.SelectedRows(0).Cells(11) is not DateTime type.  Check if it is DateTime type.
    Dim dt As DateTime
    Dim str As String = DataGridView1.SelectedRows(0).Cells(11).value
    If DateTime.TryParse(str, dt) Then
    	Console.WriteLine("{0} can be parsed into DateTime{1}", str, dt)
    Else
    	Console.WriteLine("{0} cannot be parsed into DateTim", str)
    End If
    Regards,

    Ashidacchi

    • Marked as answer by ahmeddc Tuesday, December 12, 2017 3:04 PM
    Tuesday, December 12, 2017 9:47 AM
  • I do not want to check cell because it already has a date saved from the same tool and in the same format

    I tried the next code but without interest

     
    Dim dt As DateTime = DataGridView1.SelectedRows(0).Cells(11).Value
                Me.dtDate.Value = dt

    Tuesday, December 12, 2017 10:08 AM
  • Hi,

    You don't need to insert the code I provided in real situation. It is a kind of debugging.
    I mean you need to check if value of a cell in DataGridView1 is valid as DateTime.

    Please provide its value.

    Regards,

    Ashidacchi


    • Edited by Ashidacchi Tuesday, December 12, 2017 10:19 AM
    Tuesday, December 12, 2017 10:18 AM
  • Me.dtDate.Value = Cdate(DataGridView1.SelectedRows(0).Cells(11).Value)

    Success
    Cor

    • Proposed as answer by Ashidacchi Tuesday, December 12, 2017 10:47 AM
    • Marked as answer by ahmeddc Tuesday, December 12, 2017 3:04 PM
    Tuesday, December 12, 2017 10:36 AM