Question How to take the Date value from datagridview and transfer it to a label


New member
May 14, 2022
Programming Experience
I am using and acess database
I have a form called creddatails which has a datagridview
my dgview is working properly and it has columns like Purchase invoice, credit amount, date, and time.
But whenever i use this code, my label shows date and time even though in the dgview, the column that i want took out the value only shows date.
    Private Sub dgview_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgview.CellContentClick
        If e.RowIndex >= 0 Then
            Dim row As DataGridViewRow
            row = Me.dgview.Rows(e.RowIndex)
            dtpur.Text = row.Cells(2).Value.ToString
        End If
    End Sub
my goal is to get only the date value from the dgview and transfer it to a label without time.

P.S sorry if my english is bad
Also, if the user has clicked a cell (which they have as you're in cell content click) then you can use
dtpur.Text = dgview.currentrow.Cells(2).Value.ToString

Also, a couple of suggestions.
If the cell content is blank (empty) then your code will fail - it cannot convert the .value to ToString
Rather than explicitly using (2) as the third column, use enums - what happens if you move this column or add a column at the beginning ... you have to change all the (2) to (3).... a major pain....