Results 1 to 5 of 5

Thread: [RESOLVED] SQLite date field as String to DateTime in DataGridView TextBox

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    528

    Resolved [RESOLVED] SQLite date field as String to DateTime in DataGridView TextBox

    I have a SQLite database and I store dates as ISO 8601 formatted strings ("yyyy-MM-dd HH:mm:ss").

    I have bound one of the tables from this database to a DataGridView control (dgvFuel) using a Relation (Vehicle_Fuel).

    Code:
    With bsFuel
        .DataSource = Nothing
        .DataMember = "Vehicle_Fuel"
        .DataSource = bsVehicles
        .Sort = "VehicleID, Odometer, RecDate"
    End With
    dgvFuel.DataSource = bsFuel
    I would like to show the date field values in the grid as DateTime values ("M/d/yyyy"), not string values.

    The column that has the date field in the grid is configured as follows:

    Code:
    tbc = New DataGridViewTextBoxColumn
    With tbc
        .DataPropertyName = "RecDate"
        .Name = "RecDate"
        .HeaderText = "Date"
        .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        .DefaultCellStyle.Format = "M/d/yyyy"
        .AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
        .SortMode = DataGridViewColumnSortMode.Automatic
    End With
    .Columns.Add(tbc)
    The DefaultCellStyle.Format property of the DataGridViewTextBoxColumn does not show the date as a DateTime data type.

    What do I need to do to show the dates as DateTime values in my DataGridView?
    Last edited by Mark@SF; May 31st, 2021 at 06:31 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width