Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15790

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

$
0
0
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?

Viewing all articles
Browse latest Browse all 15790

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>