Hello,

I got a problem, I can save my data to access database and in the access database field I set it to date/time.

But problem is when I get the value out from the database.. the format is always month/day/year hour:minutes:seconds
example today:
5/2/2011 12:00:00

How to get the value into listview becoming May/2/2011 without the hour
Here's my code to get it from database

ListView1.Items(i).SubItems.Add(dt.Rows(i)(14).ToString)

The second problem is..
When I would like to edit, how can the datetimepicker get the listview value ?
Here is the code when I click edit button, the datetimepicker1 will get the listview1 date.

Here my code:

DateTimePicker1.Value = ListView1.SelectedItems(0).SubItems(14).Text

Anyone can help me please?
Thanks

info: using access 2003 (.mdb) the Date of Birth field has been set into Date/Time.

Comments
You have been answered. Mark as solved next time.

Check this out:
But be careful with the column number (as far as I can see you assign date value to 14th subitem - mine is on 2nd (Subitems[1]):

Public Sub New()
	InitializeComponent()
	listView1.Columns.Add("Id", 50, HorizontalAlignment.Left)
	listView1.Columns.Add("Date and time", -2, HorizontalAlignment.Left)
	listView1.View = View.Details
	listView1.FullRowSelect = True

	'add example data:
	Dim table As New DataTable("MyTable")
	table.Columns.Add("Id", GetType(Integer))
	table.Columns.Add("Date", GetType(DateTime))
	table.Rows.Add(1, DateTime.Today.AddDays(-1))
	table.Rows.Add(2, DateTime.Today)

	'put this data to listView:
	For Each dr As DataRow In table.Rows
		Dim lvi As New ListViewItem()
		lvi.Text = dr(0).ToString()
		lvi.SubItems.Add([String].Format("{0:MM/dd/yyyy hh:mm:ss}", Convert.ToDateTime(dr(1))))
		listView1.Items.Add(lvi)
	Next

	'create a listView event:
	listView1.SelectedIndexChanged += New EventHandler(AddressOf listView1_SelectedIndexChanged)
End Sub

Private Sub listView1_SelectedIndexChanged(sender As Object, e As EventArgs)
	If listView1.SelectedIndices.Count > 0 Then
		Dim value As String = listView1.SelectedItems(0).SubItems(1).Text
		If value IsNot Nothing Then
			dateTimePicker1.Value = Convert.ToDateTime(value)
		End If
	End If
End Sub

Edited 5 Years Ago by Mitja Bonca: n/a

ListView1.Items(i).SubItems.Add(dt.Rows(i)(14).ToString)

ListView1.Items(i).SubItems.Add(cdate(dt.Rows(i)(14)).ToShortDateString)

datetimepicker1.value = cdate(listview1.items(i).subitems(x).text)
This question has already been answered. Start a new discussion instead.