none
Windows Calendar VB SelectedDates

    Question

  • In a Web application in VB I can use selectedDates to get all the selected days.  In a Windows application in VB I do not find a SelectedDates.  How do I get the values of all the dates selected in a Windows VB Calendar?

    Edcal

    Thursday, December 07, 2017 10:23 PM

All replies

  • You would use SelectionRange property which has a start and end date where you can from this get dates between.

    Here is a iterator method that will do this.

    Public Iterator Function EachDay(ByVal pFrom As Date, ByVal pThru As Date) As IEnumerable(Of Date)
        Dim day = pFrom.Date
    
        Do While day.Date <= pThru.Date
            Yield day
            day = day.AddDays(1)
        Loop
    End Function

    Perhaps in a button click event

    Dim selectedRange As SelectionRange = MonthCalendar1.SelectionRange
    For Each day As DateTime In EachDay(selectedRange.Start, selectedRange.End)
        Console.WriteLine(day)
    Next


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, December 07, 2017 10:42 PM
    Moderator
  • How do I get the values of all the dates selected in a Windows VB Calendar?

    Do you mean this:
    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.monthcalendar?view=netframework-4.7.1
    https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/monthcalendar-control-overview-windows-forms

    The example in the class definition above shows how to select a date range.  It is not possible to select a number of non-contiguous dates.

    Thursday, December 07, 2017 10:43 PM
  •  If your question about re-sizing the MonthCalendar control from the other day (link below) has been answered,  then please remember to go back to that question thread and mark the post or posts that answered your question as the answer(s).  Thanks

    VS2015 using VB - Month Calendar


    If you say it can`t be done then i`ll try it

    Thursday, December 07, 2017 10:57 PM
  • Hi Edward, as asked by IronRazerz, if your prior question has been resolved please mark one or more replies which assisted you and if not resolved please respond back in that post if more assistance is needed.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, December 07, 2017 11:36 PM
    Moderator
  • Hi Edcal,

    >>How do I get the values of all the dates selected in a Windows VB Calendar?

    Also try this:

    Public Class Form6
        Private dt, startDate, endDate As DateTime
        Private Sub MonthCalendar1_MouseDown(sender As Object, e As MouseEventArgs) Handles MonthCalendar1.MouseDown
            startDate = MonthCalendar1.SelectionStart
        End Sub
    
        Private Sub MonthCalendar1_MouseUp(sender As Object, e As MouseEventArgs) Handles MonthCalendar1.MouseUp
            RichTextBox1.Clear()
            endDate = MonthCalendar1.SelectionEnd
            dt = startDate
            While dt < endDate
                RichTextBox1.Text += Environment.NewLine + dt.ToShortDateString()
                dt = dt.AddDays(1)
            End While
        End Sub
    End Class

    Regards,

    Stanly


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 08, 2017 7:25 AM