0
votes

I have a ListView where ID and date is entered. The date is in the format dd/MM/yyyy.

enter image description here

In the SelectedIndexChanged Property I have written this

If lvRecruitmentList.SelectedItems.Count > 0 Then
   txtID.Text = lvRecruitmentList.SelectedItems(0).Text
   dtpRecievedOn.Text = lvRecruitmentList.SelectedItems(0).SubItems(1).Text
End If

In the dtpRecievedOn DateTimePicker, the Date is displayed like this

enter image description here

I have set the following properties via designer

dtpRecievedOn.Format = Custom
dtpRecievedOn.CustomFormat = "dd/MM/yyyy"

Edit 1 :

Notice that in the ListView the Date is in the format dd/MM/yyyy and in the dtpRecievedOn the Date is in the format MM/dd/yyyy.

How can I make dtpRecievedOn display date in the format dd/MM/yyyy

2
I am sorry, but I don't understand your problem? What is wrong, and what is it that you expected? - Fredrik Mörk

2 Answers

3
votes

You'll want to set the Value of the DateTimePicker as opposed to the Text. You can use DateTime.ParseExact or DateTime.TryParseExact to change your text date to a DateTime. Replace your third line with:

Dim selectedDate As DateTime
Dim format As String = "dd/MM/yyyy"
Dim txt As String = lvRecruitmentList.SelectedItems(0).SubItems(1).Text
selectedDate = DateTime.ParseExact(txt, format, CultureInfo.InvariantCulture)
dtpRecievedOn.Value = selectedDate
-1
votes
Dim str As String() = "2/1/2000".Split("/"C)
Dim dt As New DateTime(Convert.ToInt16(str(2)), Convert.ToInt16(str(1)), Convert.ToInt16(str(0)))
dateTimePicker1.Value = dt.Date