How To: Get Selected Date from MonthCalendar control

VB.NET

Private Sub MonthCalendar1_DateChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged

'Display the dates for selected range
Label1.Text = "Dates Selected from :" & (MonthCalendar1.SelectionRange.Start() & " to " & MonthCalendar1.SelectionRange.End)

'To display single selected of date
'MonthCalendar1.MaxSelectionCount = 1

'To display single date use MonthCalendar1.SelectionRange.Start/ MonthCalendarSelectionRange.End
Label2.Text = "Date Selected :" & MonthCalendar1.SelectionRange.Start

End Sub

C#

private void MonthCalendar1_DateChanged(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
//Display the dates for selected range
Label1.Text = "Dates Selected from :" + (MonthCalendar1.SelectionRange.Start() + " to " + MonthCalendar1.SelectionRange.End);

//To display single selected of date
//MonthCalendar1.MaxSelectionCount = 1;

//To display single selected of date use MonthCalendar1.SelectionRange.Start/ MonthCalendarSelectionRange.End
Label2.Text = "Date Selected :" + MonthCalendar1.SelectionRange.Start;
}

Published Tuesday, August 15, 2006 10:03 PM by SushilaSB
Filed under:

Comments

Wednesday, February 27, 2008 8:01 AM by semauel

# re: How To: Get Selected Date from MonthCalendar control

hi there can you help me with this bit of code l want it to return results for a particualar dateelected on the calender

below the query is firing blanks

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

       'If ConnectionState.Open Then

       '    objConnection.Close()

       'Else

       '    objConnection.Open()

       Try

           'Me.txtDate.Text = CDate(Date.FromOADate(Val(txtDate.Text)))

           objDataAdapter.SelectCommand = New SqlCommand()

           objDataAdapter.SelectCommand.Connection = objConnection

           objDataAdapter.SelectCommand.CommandText = "select * from Calender where dDate = '" + txtDate.Text + "'"

           objDataAdapter.SelectCommand.CommandType = CommandType.Text

           ' Open the database connection...

           objConnection.Open()

           ' Fill the DataSet object with data...

           objDataAdapter.Fill(objDataSet, "calenders")

           ' Close the database connection...

           objConnection.Close()

           ' Set the DataGridView properties to bind it to our data...

           DataGridView1.AutoGenerateColumns = True

           DataGridView1.DataSource = objDataSet

           DataGridView1.DataMember = "calenders"

           'Clean up

           'objDataAdapter = Nothing

           'objConnection = Nothing

       Catch ex As Exception

           MsgBox("Please try again ")

       End Try

       '  End If

   End Sub

Tuesday, March 1, 2011 7:33 AM by Rajesh V.R

# re: How To: Get Selected Date from MonthCalendar control

Hai, I am new in VC++, I wish to know that "how to get the selected date from a MonthCalender control into an Edit control", in Visual C++ Win32 Programming...

Friday, March 25, 2011 3:51 AM by sakthi

# re: How To: Get Selected Date from MonthCalendar control

i want a simple coding how to retrieve last(previous) date from database...

Thursday, March 1, 2012 11:54 AM by satish r. s

# re: How To: Get Selected Date from MonthCalendar control

label1.Text = Convert .ToString ( monthCalendar1.SelectionRange.Start );

Saturday, May 5, 2012 10:52 AM by Talbi Elhadi

# re: How To: Get Selected Date from MonthCalendar control

label1.Text = Convert .ToString ( monthCalendar1.SelectionRange.Start );

Wednesday, May 9, 2012 7:55 AM by prasad

# re: How To: Get Selected Date from MonthCalendar control

label1.Text = Convert .ToString ( monthCalendar1.SelectionRange.Start );

Sunday, July 1, 2012 8:47 AM by mido

# re: How To: Get Selected Date from MonthCalendar control

how to create a digital clock ?

Wednesday, July 11, 2012 2:14 AM by farid

# re: How To: Get Selected Date from MonthCalendar control

thx :) trhat was vewry helpful