none
VBNET2008 PopUpCalendar Date Format from MM/ DD/ YYYY to DD/ MM/ YYYY When click on the Date to select RRS feed

  • Question

  • Hullo  Important Friends,

    I do need your help. Please help me.

    I am using VBNET2008 to developer a Form of PopUpCalendar for user to select the  PopUpCalendar date format of  MM/DD/YYYY.  When click to select a  Date from the PopUpCalender and to display the selected date on part of the PopUpCalendar Form in this format “DD/MM/YYYY.

    When then PopUpcalendar Button of OK Click, the desire that the Dataformat should be dd/mm/yyyy to transfer it to the calling Form.

    Apparently the  PopUpCalendar Coding Scripts are not workling. 

    Here are the overall Coding of PopUpCalendar Form

    Public Class FrmPopUpCalendar

        '-- declare variables ----

        Dim PselectDate As String = Nothing

        Dim Pcancel As String = Nothing

    Private Sub FrmPopUpCalendar_Load(ByVal sender As System.Object, ByVal e As ystem.EventArgs) Handles MyBase.Load

            Me.txtDisplayDate.Text = Nothing

            PselectDate = Nothing

        End Sub

    Private Sub MonthCalendar1_DateSelected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs)

                                                           Handles MonthCalendar1.DateSelected

            PropSelectDate = e.Start.ToShortDateString

        End Sub

    Public Property PropSelectDate() As String

            Get

                Return PselectDate

            End Get

            Set(ByVal value As String)

                 PselectDate = value.ToString.Format("[dd/mm/yyyy]")   ‘--- not working ----

                 Me.txtDisplayDate.Text = PselectDate.ToString         ‘--- not working ----

            End set

    End Class

    Thank you very much for your help to Format selected Date as DD / MM / YYYY

    Cheers,

    Have a Good Day

    Lennie Kuah


    Thank you very Much, Have a Good Day. Cheers, Lennie

    Tuesday, August 28, 2012 11:43 AM

Answers

  • Hi Lennie,

    Welcome to the MSDN Forum.

    The reason you got that error message is this: http://msdn.microsoft.com/en-us/library/system.string.tostring(v=vs.110).aspx

    For String, there only two overload version of ToString method.

    To achieve your goal, please try to change the set method like this:

            Set(ByVal value As Date)
    
                 PselectDate = value.ToString("[dd/mm/yyyy]")   
                 Me.txtDisplayDate.Text = PselectDate.ToString         
            End set

    And you can set this property like this:

    PropSelectDate = e.Start

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 29, 2012 4:16 PM
    Moderator

All replies

  • Hi,

    Please try this:

    string format = "dd/mm/yyyy";    
    PSelectDate=value.ToString(format);


    Regards, http://www.shwetalodha.blogspot.in/

    Tuesday, August 28, 2012 2:44 PM
  • Hullo Friendly Shwea Jain

    I did change my coding based on your suggestion

    String format = "dd/mm/yyyy";   
    PSelectDate=value.ToString(format);

    I am very surprised that it does generate this

    Error message:

    Format generate error message :
    Unable to cast object of type 'System.String' to type 'System.IFormatProvider'.

    Please help me.

    Thank you very much

    Cheers,

    Lennie

    New Zealand


    Thank you very Much, Have a Good Day. Cheers, Lennie

    Wednesday, August 29, 2012 7:48 AM
  • Hi Lennie,

    The code I gave you is of C# and I tested this on machine. It is not giving any error. Please check, there might be different syntax in VB.Net to represent the same.


    Regards, http://www.shwetalodha.blogspot.in/

    Wednesday, August 29, 2012 1:10 PM
  • Hi Lennie,

    Welcome to the MSDN Forum.

    The reason you got that error message is this: http://msdn.microsoft.com/en-us/library/system.string.tostring(v=vs.110).aspx

    For String, there only two overload version of ToString method.

    To achieve your goal, please try to change the set method like this:

            Set(ByVal value As Date)
    
                 PselectDate = value.ToString("[dd/mm/yyyy]")   
                 Me.txtDisplayDate.Text = PselectDate.ToString         
            End set

    And you can set this property like this:

    PropSelectDate = e.Start

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 29, 2012 4:16 PM
    Moderator