How to get date has just be selected (click)

9 posts, 0 answers
  1. Thanh
    Thanh avatar
    9 posts
    Member since:
    Dec 2015

    Posted 21 Jan 2016 Link to this post

    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

  2. Stefan
    Admin
    Stefan avatar
    2902 posts

    Posted 22 Jan 2016 Link to this post

    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 handler 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
  3. Thanh
    Thanh avatar
    9 posts
    Member since:
    Dec 2015

    Posted 22 Jan 2016 in reply to Stefan Link to this post

    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

  4. Stefan
    Admin
    Stefan avatar
    2902 posts

    Posted 22 Jan 2016 Link to this post

    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 build-in 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
  5. Brian
    Brian avatar
    8 posts
    Member since:
    Apr 2010

    Posted 25 May in reply to Stefan Link to this post

    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.

  6. Dess
    Admin
    Dess avatar
    1939 posts

    Posted 26 May Link to this post

    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.
  7. Brian
    Brian avatar
    8 posts
    Member since:
    Apr 2010

    Posted 31 May in reply to Dess Link to this post

    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.

  8. Dess
    Admin
    Dess avatar
    1939 posts

    Posted 01 Jun Link to this post

    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.
  9. Brian
    Brian avatar
    8 posts
    Member since:
    Apr 2010

    Posted 01 Jun in reply to Dess Link to this post

    Dess,

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

Back to Top