1,105,384 Community Members

ReadOnly Datetime Picker VB>NET

Member Avatar
thanzeem7
Newbie Poster
5 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Can anyone know how to make a readonly datetime picker in VB.NET?

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

How can the user pick the date and time if it's read only? You need some clarification there. If you want to display the date and time as read only use a label and the built in tostring functions of the datetime class.

Member Avatar
azareth
Posting Whiz in Training
247 posts since Apr 2012
Reputation Points: 5 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 0 [?]
 
0
 

that's confusing..

If you want to display the date and time as read only use a label and the built in tostring functions of the datetime class.
yeah, just do this instead

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
1
 

I guess if you you have it formatted to a short date format, then allowing the user to invoke the dropdown to show the MonthCalndar may be of some use.

Anyways, making a readonly DTP control is fairly easy.

Public Class ReadOnlyDTP
   Inherits DateTimePicker
   Public Shadows Property Value() As DateTime
      Get
         Return MyBase.Value
      End Get
      Set(ByVal value As DateTime)
         ' Need to set values in correct order 
         ' to prevent internal validation error
         Select Case value
            Case Is < MyBase.Value
               MyBase.MinDate = value
               MyBase.Value = value
               MyBase.MaxDate = value
            Case Is > MyBase.Value
               MyBase.MaxDate = value
               MyBase.Value = value
               MyBase.MinDate = value
         End Select
      End Set
   End Property 'Value

   Const WM_Char As Int32 = &H102
   Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
      ' prevent keyboard changes to the fields
      If m.Msg = WM_Char Then Exit Sub
      MyBase.WndProc(m)
   End Sub
End Class

Add this to your project, build the project and it should showup in your ToolBox if your VS is configured to do so (it is the default setting).

Member Avatar
tinstaafl
Postaholic
2,012 posts since Jun 2010
Reputation Points: 559 [?]
Q&As Helped to Solve: 402 [?]
Skill Endorsements: 35 [?]
 
0
 

then allowing the user to invoke the dropdown to show the MonthCalndar may be of some use

Yeah I can see that. You could use the ValueChanged event to reset the value to what you need, and just ignore the users input.

Member Avatar
M.Waqas Aslam
Practically a Posting Shark
837 posts since Aug 2011
Reputation Points: 67 [?]
Q&As Helped to Solve: 137 [?]
Skill Endorsements: 4 [?]
Featured
 
0
 

hello !

you can simple disable the datetimepicker like this

Me.dateTimePicker1.Enabled = false

Regards

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article