Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTimePicker...

Status
Not open for further replies.

Kris11

Programmer
Jan 31, 2003
278
US
Hi,

Any of you know how to set the start day on a DateTimePicker to Monday rather than the default one which is Sunday. What I am trying is instead of DateTimePicker shwoing from Sun. to Sat., I want it to be from Mon. to Sun. Any ideas??? I found a code in VB which says we can do the same using an API call but don't know how to convert this to VB .NET. This is what it says


In the declarations of a bas module

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As
Long, ByVal wMsg As _
Long, ByVal
wParam As Long, lParam As Any) As Long
Public Const DTM_GETMONTHCAL = DTM_FIRST + 8
Public Const MCM_FIRST = &H1000
Public Const MCM_SETFIRSTDAYOFWEEK = MCM_FIRST + 15
Public Const EM_GETLINECOUNT = &HBA
____________________________________________________________
In theDropDown Sub of the DTPicker
This will set the first day to Monday

Private Sub DPPIcker1_DropDown()

Dim calHwnd As Long

calHwnd = SendMessage(DPPicker1.hwnd, DTM_GETMONTHCAL, 0&, ByVal 0&)
SendMessage calHwnd, MCM_SETFIRSTDAYOFWEEK, 0&, ByVal 6&
End Sub


Thanks
 
Hi Kriss
You can do it if you use DateTimeFormatInfor.FirstDayOfWeek
property,its a part of
System.Globalization library
To create a DateTimeFormatInfo for a specific culture, create a CultureInfo for that culture and retrieve the CultureInfo.DateTimeFormat property.
So it will change the culture and ur datepicker will show what you wants
Nouman

 
Nouman,

that didn't work. This is what I did,


Dim dtfLocal As System.Globalization.DateTimeFormatInfo
Dim ciLocalCulture As New System.Globalization.CultureInfo("en-US")

dtfLocal = New System.Globalization.DateTimeFormatInfo
dtfLocal.FirstDayOfWeek = DayOfWeek.Monday
ciLocalCulture.DateTimeFormat = dtfLocal
Application.CurrentCulture = ciLocalCulture


Still my datetimepicker shows Sun. to Sat. not Mon. to Sun.

Any idea?

-Kris
 
Hi Kris
Sorry its work perfect with Calender Control
The Calender Control has property called FirstDayOfWeek,which u can set to any day
But for datetimepicker i have to check but it should work once the culture is set let me check and if i found something with datetimepicker will let u know but if u can use calender control then it has property called FirstDayOfWeek
Regards
Nouman
 
Hi Kris
you can use API
but i see some errors

1) To declare a DLL procedure
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd AsLong, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

2) define Windows API Constants

Const DTM_GETMONTHCAL = DTM_FIRST + 8 'Whats DTM_FIRST? and also these Constants are not defined in WinUser.h file
Const MCM_FIRST = &H1000
Const MCM_SETFIRSTDAYOFWEEK = MCM_FIRST + 15
Const EM_GETLINECOUNT = &HBA

3) call the API
calHwnd = SendMessage(DPPicker1.hwnd, DTM_GETMONTHCAL, 0&, ByVal 0&)
SendMessage calHwnd, MCM_SETFIRSTDAYOFWEEK, 0&, ByVal 6&

Nouman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top