Click here to Skip to main content
15,947,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me out I'm creating a customized calendar but I want to start the week with Monday,

here is the code--
VB
Public Sub DrawCalendar()
     IsInitializing = True

     Dim intNumberOfDays As Integer
     Dim datFirstDay As Date

     Dim x As Integer
     Dim i As Integer
     'Clean the txtDay / lblDay
     For i = 0 To 41
         lblDay(i).Text = ""
         lblDay(i).BackColor = Color.FromKnownColor(KnownColor.Control)
         lblDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlText)
         txtDay(i).BackColor = Color.FromKnownColor(KnownColor.Window)
         txtDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlText)
         picDay(i).BackgroundImage = Nothing
         txtDay(i).Text = ""
         picDay(i).Visible = True
     Next i

     HeaderLable.Text = _SelectedDate.ToString("MMMM yyyy")
     MonthCombo.SelectedIndex = _SelectedDate.Month - 1
     YearUpDown.Value = _SelectedDate.Year

     intNumberOfDays = _SelectedDate.DaysInMonth(_SelectedDate.Year, _SelectedDate.Month)
     datFirstDay = CDate(_SelectedDate.Month & "/" & 1 & "/" & _SelectedDate.Year)
     x = 1

     'Gets an array list of days

     Dim trgDate As Date

     Dim dv As DataView = Nothing
     If Not DataSource Is Nothing Then
         If TableName.Length > 0 Then
             If DateMember.Length > 0 Then
                 If TimeMember.Length > 0 Then
                     Try
                         dv = DataSource.DefaultViewManager.CreateDataView(DataSource.Tables(TableName))
                     Catch ex As Exception
                         MessageBox.Show(ex.Message)
                     End Try
                 End If
             End If
         End If
     End If

     For i = Weekday(datFirstDay) - 1 To intNumberOfDays + Weekday(datFirstDay) - 2
         lblDay(i).Text = CStr(x)

         ' Today gets special background
         If _SelectedDate.Month = Now.Month And _SelectedDate.Year = Now.Year Then
             If x = Now.Day Then
                 txtDay(i).BackColor = System.Drawing.Color.LightGreen
                 lblDay(i).BackColor = System.Drawing.Color.Green
             End If
         End If

         ' show appontments
         SetAppointment(dv, New DateTime(_SelectedDate.Year, _SelectedDate.Month, x), i, False)

         x = x + 1
     Next

     'Make the picDays that aren't from the month invisible
     x = 1
     For i = 27 To 41
         If lblDay(i).Text = "" Then
             lblDay(i).Text = Str(x)
             lblDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
             SetAppointment(dv, New DateTime(_SelectedDate.AddMonths(1).Year, _SelectedDate.AddMonths(1).Month, x), i, True)
             x += 1
             txtDay(i).BackColor = Color.FromKnownColor(KnownColor.Control)
             txtDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
         End If
     Next

     x = DateTime.DaysInMonth(_SelectedDate.AddMonths(-1).Year, _SelectedDate.AddMonths(-1).Month)
     For i = 7 To 0 Step -1
         If lblDay(i).Text = "" Then
             lblDay(i).Text = Str(x)
             lblDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
             SetAppointment(dv, New DateTime(_SelectedDate.AddMonths(-1).Year, _SelectedDate.AddMonths(-1).Month, x), i, True)
             x -= 1
             txtDay(i).BackColor = Color.FromKnownColor(KnownColor.Control)
             txtDay(i).ForeColor = Color.FromKnownColor(KnownColor.ControlDark)
         End If
     Next

     IsInitializing = False
 End Sub
Posted
Updated 30-Sep-14 20:39pm
v2

1 solution

 
Share this answer
 
Comments
Gracestoperez 1-Oct-14 2:44am    
Is it this code?


Dim WeekNumber As Integer = DatePart(DateInterval.WeekOfYear, Date.Today, _
FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFourDays)


Can you help me out where I can apply it on my code above? Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900