This is a migrated thread and some comments may be shown as answers.

How to get date has just be selected (click)

8 Answers 484 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Thanh
Top achievements
Rank 1
Thanh asked on 22 Jan 2016, 04:56 AM

Hi,

 

I have a week is selected, then I click a date more, how can I get the last date I have just clicked.

 

Look forward your reply,

Pham Thanh

8 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 22 Jan 2016, 07:16 AM
Hi Thanh,

Thank you for writing.

RadCalendar features SelectionChanging event, which will get triggered when the selection has been changed. In your scenario, in the event you can access the e.NewDates property to get the newly selected date.

More information on the events provided by RadCalendar, can be found here.

I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Thanh
Top achievements
Rank 1
answered on 22 Jan 2016, 07:41 AM

Hi Stefan,

I want to describe about my scenario. When I click on a day, I want whole week is selected instead of one day, so I can not use SelectionChanging  event, because when user click, the SelectionChanging is raised, then I get the selected date by e.NewDates, I calculate and add dates in week from that date, then add to SelectedDates property, this will raise SelectionChaging again.

 Therefore, I don't use SelectionChanging event, I use Click event and get the last clicked date from FocusedDate Property. I have just found this property, and it work find.

 Thank for your answer.

Pham Thanh

0
Stefan
Telerik team
answered on 22 Jan 2016, 11:43 AM
Hello Thanh,

I am glad you found a way to handle your scenario, indeed the Click event is the other option.

I would like to just add, that row/column selection is available as functionality with the column/row headers. Here you can find more information on this matter: http://docs.telerik.com/devtools/winforms/calendar/customizing-behavior/column-and-row-headers and also here is a small snippet:
radCalendar1.AllowMultipleSelect = true;
radCalendar1.ShowRowHeaders = true;
radCalendar1.AllowRowHeaderSelectors = true;

I hope that you find this information useful.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Brian
Top achievements
Rank 1
answered on 25 May 2017, 01:33 PM

Is it possible to select more than one week per month when using the row header as the selector?  it appears that currently when I click a row header to select a week, it automatically deselects any other selections I have for the month.  Is this intended behavior?   Also - is it possible to determine if the cell I have clicked on is a header cell versus a regular calendar cell?

Thanks.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 May 2017, 11:26 AM
Hello Brian, 

Thank you for writing.  

The multiple selection should be kept no matter if you click a date cell or the header cell. I have logged it in our feedback portal and I have added a vote for it on your behalf. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

Currently, the possible solution that I can suggest is to use the MouseDown event to store the currently selected cells and then on MouseUp restore the missing selection:

public class MyCalendar : RadCalendar
{
    List<DateTime> selectedDays = new List<DateTime>();
 
    protected override void OnMouseDown(MouseEventArgs e)
    {
        CalendarCellElement cell = this.ElementTree.GetElementAtPoint(e.Location) as CalendarCellElement;
        if (cell != null)
        {
            bool isHeader = (bool)cell.GetValue(CalendarCellElement.IsHeaderCellProperty);
            if (isHeader)
            {
                selectedDays.Clear();
                foreach (DateTime date in this.SelectedDates)
                {
                    selectedDays.Add(date);
                }
            }
        }
        base.OnMouseDown(e);
    }
 
    protected override void OnMouseUp(MouseEventArgs e)
    {
        base.OnMouseUp(e);
        foreach (DateTime date in selectedDays)
        {
            if (!this.SelectedDates.Contains(date))
            {
                this.SelectedDates.Add(date);
            }
        }
    }
 
    public override string ThemeClassName 
    {
        get
        {
            return typeof(RadCalendar).FullName; 
        }
    }
}

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brian
Top achievements
Rank 1
answered on 31 May 2017, 02:28 PM

Thanks Dess, this worked great for adding multiple selections, but it no longer allows me to deselect a week.  For example, I select 7 weeks all using the week headers, but then I decide I want to deselect one of the weeks, I can no longer do that.   Any suggestions on how to achieve being able to select and deselect multiple weeks using the week headers?

Thanks.

PS - I sure wish you guys offered a "WeekHeaderClicked" event to give us programmers more control over what to do when a week header is clicked.  It would even be helpful if the date value of the week header cell wasn't the 1st day of the month.  Just a suggestion.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Jun 2017, 08:10 AM
Hello Brian, 

Thank you for writing back. 

Here is the modified code snippet demonstrating how to unselect the selected row in RadCalendar:
protected override void OnMouseDown(MouseEventArgs e)
{
    CalendarCellElement cell = this.ElementTree.GetElementAtPoint(e.Location) as CalendarCellElement;
    if (cell != null)
    {
        bool isHeader = (bool)cell.GetValue(CalendarCellElement.IsHeaderCellProperty);
        if (isHeader)
        {
            MonthViewElement monthView = this.CalendarElement.CalendarVisualElement as MonthViewElement;
 
            foreach (CalendarCellElement c in monthView.TableElement.Children)
            {
                if (cell.Row == c.Row && c.Selected)
                {
                    this.SelectedDates.Remove(c.Date);
                }
            }
            selectedDays.Clear();
            foreach (DateTime date in this.SelectedDates)
            {
                selectedDays.Add(date);
            }
        }
         
    }
    base.OnMouseDown(e);
}

Note that this is just a sample approach and it may not cover all possible cases. Note that the fix is scheduled for the upcoming service pack in the middle of June.

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Brian
Top achievements
Rank 1
answered on 01 Jun 2017, 01:37 PM

Dess,

Thanks so much!  This should be fine until the service pack comes out.

Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Thanh
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Thanh
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or