vb.netdatagridview

DataGridView I want to format the date in the tenth cell from the current date 2024-11-18T10:59:00.000+0000 to 2024-11-18


DataGridView I want to format the date in the tenth cell

from 2024-11-18T10:59:00.000+0000

to 2024-11-18

The history appears to be very long and all I want is history. The date is showing too long and what I want is just the date Column number in cell 10

I tried using this it didn't work

For i = 0 To DataGridView.Rows.Count - 1
    DataGridView.Rows(i).Cells(10).Value.DefaultCellStyle.Format = "yyyy-MM-dd"
Next

Solution

  • You can on form load make

     DataGridView1.Columns(10).DefaultCellStyle.Format = "yyyy-MM-dd"
    

    This will change the style of the date column

    And you apply it like this in the class of your and FORM_Load

    Private Sub Start_frm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        'add datasource
        DataGridView1.DataSource = dataset_table.Tables(0)
    
        DataGridView1.Columns(0).Width = 110
        DataGridView1.Columns(1).Width = 115
        DataGridView1.Columns(2).DefaultCellStyle.Format =  "yyyy-MM-dd"
        DataGridView1.Columns(2).Width = 135
        DataGridView1.Columns(3).DefaultCellStyle.Format = "dd.MM.yyyy HH:mm:ss"
        DataGridView1.Columns(3).Width = 125
        DataGridView1.Columns(4).DefaultCellStyle.Format =  "yyyy-MM-dd"
        DataGridView1.Columns(4).Width = 110
        DataGridView1.Columns(5).DefaultCellStyle.Format =  "yyyy-MM-dd"
        DataGridView1.Columns(5).Width = 110
        DataGridView1.Columns(6).DefaultCellStyle.Format =  "yyyy-MM-dd"
        DataGridView1.Columns(6).Width = 110
        DataGridView1.Columns(8).DefaultCellStyle.Format = "dd.MM.yyyy HH:mm:ss"
        DataGridView1.Columns(8).Width = 110
        DataGridView1.Columns(10).Width = 120
        DataGridView1.Columns(11).Width = 110
    
    End Sub
    

    if your datasource is string

    you can split the value at the tenth character

     For i = 0 To DataGridView.Rows.Count - 1
         DataGridView1.Rows(i).Cells(10).Value = DataGridView1.Rows(i).Cells(10).Value.ToString.Substring(0, 10)
    
     Next