calendar control

jvcoach23

Well-known member
Joined
May 22, 2003
Messages
192
Location
Saybrook, IL
Im new to vb.net and am trying to work on a calendar control. How do you size the of the calendar. For example, i am going to want to read from an arry into the calendar control and have data show up inside each day of the calendar. How do you control the size of each day cell.

in looking around the net I also have found a code synbit that says to populate the calendar, you use the

While MyReader.Read
MyCalendar.SelectedDates.Add(MyReader.Item("MyDate"))
End While

so in addition to helping me out with the sizing issue (I only want to display one month at a time, can you tell me if the above is the correct way to go about adding data to the calendar control. Thanks
 
Im still working on that.. I did research for about 4 hours to try to find different ways of populating it.. once I get something Ill post it. thanks
 
I am including my code so far. I am using a stored procedure to fill a datagrid just so that I can make sure that my dataset has data. What Im wanting to do is fill the calendar control with the data from the stored procedure result set.

Anyway, any help would be great. Im still trying to understand.

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
create database connection
Dim myConnection As SqlConnection = New SqlConnection("server=(local); database=CallSchedule; trusted_connection=true;")

create the dataAdapter
Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter
Dim myDataSet As DataSet = New DataSet
Dim sqlspScheduleList As SqlCommand = New SqlCommand
Dim myDataReader As SqlDataReader



Public Sub GetDBItems()


With Me.sqlspScheduleList
.Connection = Me.myConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "spScheduleList"
End With

Me.myDataAdapter.SelectCommand = Me.sqlspScheduleList

With Me.sqlspScheduleList.Parameters
.Add(New SqlParameter("@intTblInstitutionId", SqlDbType.Int))
.Add(New SqlParameter("@dtmStartDate", SqlDbType.DateTime))
.Add(New SqlParameter("@dtmStopDate", SqlDbType.DateTime))
.Add(New SqlParameter("@vcShiftName", SqlDbType.VarChar, 50))
.Add(New SqlParameter("@cInitials", SqlDbType.Char, 4))
.Add(New SqlParameter("@debug", SqlDbType.Int))
.Add(New SqlParameter("@ErrorNo", SqlDbType.Int, 4, System.Data.ParameterDirection.Output, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
.Add(New SqlParameter("@ErrorMsg", SqlDbType.VarChar, 50, System.Data.ParameterDirection.Output, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
End With

Dim StartDate As Date
Dim StopDate As Date
Dim ShiftName As String
Dim Initials As String


StartDate = "6/15/2003"
StopDate = "6/30/2003"
ShiftName = "non"
Initials = "mm"

With Me.sqlspScheduleList
.Parameters("@intTblInstitutionId").Value = 1
.Parameters("@dtmStartDate").Value = StartDate
.Parameters("@dtmStopDate").Value = StopDate
.Parameters("@vcShiftName").Value = ShiftName
.Parameters("@cInitials").Value = Initials
.Parameters("@debug").Value = 0
End With

Me.myDataSet = New DataSet

open connection
Me.myConnection.Open()

Try
Me.sqlspScheduleList.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex)
Throw (ex)
End Try
Me.myConnection.Close()



Fill the DataAdapter
Me.myDataAdapter.Fill(Me.myDataSet, "CalendarList")

populate the datagrid
Me.grdGrid1.DataSource = Me.myDataSet
Me.grdGrid1.DataMember = "CalendarList"
End Sub

Public Structure MyDates
Dim _dtmDates As Date
Dim _Shift As String
Dim _InstitutionName As String
Dim _Initials As String
Dim _ScheduleId As Integer
End Structure

Public MyCollection As Collection

Public tempDate As DateTime


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

This call is required by the Windows Form Designer.
InitializeComponent()

Add any initialization after the InitializeComponent() call

End Sub

Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

NOTE: The following procedure is required by the Windows Form Designer
It can be modified using the Windows Form Designer.
Do not modify it using the code editor.
Friend WithEvents Calendar1 As System.Windows.Forms.MonthCalendar
Friend WithEvents grdGrid1 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Calendar1 = New System.Windows.Forms.MonthCalendar
Me.grdGrid1 = New System.Windows.Forms.DataGrid
CType(Me.grdGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()

Calendar1

Me.Calendar1.Location = New System.Drawing.Point(64, 96)
Me.Calendar1.Name = "Calendar1"
Me.Calendar1.TabIndex = 0

grdGrid1

Me.grdGrid1.DataMember = ""
Me.grdGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.grdGrid1.Location = New System.Drawing.Point(72, 392)
Me.grdGrid1.Name = "grdGrid1"
Me.grdGrid1.Size = New System.Drawing.Size(728, 168)
Me.grdGrid1.TabIndex = 1

Form1

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(896, 598)
Me.Controls.Add(Me.grdGrid1)
Me.Controls.Add(Me.Calendar1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.grdGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tempDate = Me.Calendar1.TodayDate
GetDBItems()

MyCollection = New Collection
Dim temp As MyDates

While (mydatareader.read())
temp = New MyDates

temp._dtmDates = CDate(myDataReader.Item("dtmDate"))
temp._Shift = myDataReader.Item("vcShiftName")
temp._InstitutionName = myDataReader.Item("vcInstitutionName")
temp._Initials = myDataReader.Item("cInitials")
temp._ScheduleId = CInt(myDataReader.Item("intTblScheduleId"))

MyCollection.Add(temp)

End While
For Each mycollection.Item
If DayTextHasChanged = True Then
Exit For
End If
MultipleItemDay = False
If dayhold = item._dtmDates Then
dayhold = item._dtmDates
Else
MultipleItemDay = True
End If



If MultipleItemDay = False Then
temp(New stringbuilder)
Else
temp.append("<br>")
End If

temp.append(item._shift.tostring())
DayTextHasChanged = True
Next

End Sub


End Class


suggestions welcome. Im ready to learn
 
Im trying that out.. so if this doesnt look right.....
Code:
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
create database connection
Dim myConnection As SqlConnection = New SqlConnection("server=(local); database=CallSchedule; trusted_connection=true;")

create the dataAdapter
Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter
Dim myDataSet As DataSet = New DataSet
Dim sqlspScheduleList As SqlCommand = New SqlCommand
Dim myDataReader As SqlDataReader



Public Sub GetDBItems()


With Me.sqlspScheduleList
.Connection = Me.myConnection
.CommandType = CommandType.StoredProcedure
.CommandText = "spScheduleList"
End With

Me.myDataAdapter.SelectCommand = Me.sqlspScheduleList

With Me.sqlspScheduleList.Parameters
.Add(New SqlParameter("@intTblInstitutionId", SqlDbType.Int))
.Add(New SqlParameter("@dtmStartDate", SqlDbType.DateTime))
.Add(New SqlParameter("@dtmStopDate", SqlDbType.DateTime))
.Add(New SqlParameter("@vcShiftName", SqlDbType.VarChar, 50))
.Add(New SqlParameter("@cInitials", SqlDbType.Char, 4))
.Add(New SqlParameter("@debug", SqlDbType.Int))
.Add(New SqlParameter("@ErrorNo", SqlDbType.Int, 4, System.Data.ParameterDirection.Output, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
.Add(New SqlParameter("@ErrorMsg", SqlDbType.VarChar, 50, System.Data.ParameterDirection.Output, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
End With

Dim StartDate As Date
Dim StopDate As Date
Dim ShiftName As String
Dim Initials As String


StartDate = "6/15/2003"
StopDate = "6/30/2003"
ShiftName = "non"
Initials = "mm"

With Me.sqlspScheduleList
.Parameters("@intTblInstitutionId").Value = 1
.Parameters("@dtmStartDate").Value = StartDate
.Parameters("@dtmStopDate").Value = StopDate
.Parameters("@vcShiftName").Value = ShiftName
.Parameters("@cInitials").Value = Initials
.Parameters("@debug").Value = 0
End With

Me.myDataSet = New DataSet

open connection
Me.myConnection.Open()

Try
Me.sqlspScheduleList.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex)
Throw (ex)
End Try
Me.myConnection.Close()



Fill the DataAdapter
Me.myDataAdapter.Fill(Me.myDataSet, "CalendarList")

populate the datagrid
Me.grdGrid1.DataSource = Me.myDataSet
Me.grdGrid1.DataMember = "CalendarList"
End Sub

Public Structure MyDates
Dim _dtmDates As Date
Dim _Shift As String
Dim _InstitutionName As String
Dim _Initials As String
Dim _ScheduleId As Integer
End Structure

Public MyCollection As Collection

Public tempDate As DateTime


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

This call is required by the Windows Form Designer.
InitializeComponent()

Add any initialization after the InitializeComponent() call

End Sub

Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

NOTE: The following procedure is required by the Windows Form Designer
It can be modified using the Windows Form Designer. 
Do not modify it using the code editor.
Friend WithEvents Calendar1 As System.Windows.Forms.MonthCalendar
Friend WithEvents grdGrid1 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Calendar1 = New System.Windows.Forms.MonthCalendar
Me.grdGrid1 = New System.Windows.Forms.DataGrid
CType(Me.grdGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()

Calendar1

Me.Calendar1.Location = New System.Drawing.Point(64, 96)
Me.Calendar1.Name = "Calendar1"
Me.Calendar1.TabIndex = 0

grdGrid1

Me.grdGrid1.DataMember = ""
Me.grdGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.grdGrid1.Location = New System.Drawing.Point(72, 392)
Me.grdGrid1.Name = "grdGrid1"
Me.grdGrid1.Size = New System.Drawing.Size(728, 168)
Me.grdGrid1.TabIndex = 1

Form1

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(896, 598)
Me.Controls.Add(Me.grdGrid1)
Me.Controls.Add(Me.Calendar1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.grdGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tempDate = Me.Calendar1.TodayDate
GetDBItems()

MyCollection = New Collection
Dim temp As MyDates

While (mydatareader.read())
temp = New MyDates

temp._dtmDates = CDate(myDataReader.Item("dtmDate"))
temp._Shift = myDataReader.Item("vcShiftName")
temp._InstitutionName = myDataReader.Item("vcInstitutionName")
temp._Initials = myDataReader.Item("cInitials")
temp._ScheduleId = CInt(myDataReader.Item("intTblScheduleId"))

MyCollection.Add(temp)

End While
For Each mycollection.Item
If DayTextHasChanged = True Then
Exit For
End If
MultipleItemDay = False
If dayhold = item._dtmDates Then
dayhold = item._dtmDates
Else
MultipleItemDay = True
End If



If MultipleItemDay = False Then
temp(New stringbuilder)
Else
temp.append("<br>")
End If

temp.append(item._shift.tostring())
DayTextHasChanged = True
Next

End Sub


End Class
 
I was wondering if anyone could give me code for putting data for one day into a calendar control from a dataset. Maybe if I got that much, I could continue on my road of hard knocks.

thanks
Shannon
 
Is this the MonthCalendar control from the System.Windows.Forms namespace? From the code thats what it looks like to me. As far as I know, using this control is fairly limited. You cannot change the size of the day cells or enter data inside the days itself. The best you can do is select a range of days. At least.. from looking through various online documentation, I have yet to find a way myself. You are probably thinking of the Calendar control from ASP.NET, which is a totally different beast and is majorly complex.
 
Back
Top