RAD Studio |  |

Moving the Selection

The inherited behavior of a grid handles moving the selection in response to either arrow keys or clicks, but if you want to change the selected day, you need to modify that default behavior.

To handle movements within the calendar, override the Click method of the grid.

When you override a method such as Click that is tied in with user interactions, you will nearly always include a call to the inherited method, so as not to lose the standard behavior.

The following is an overridden Click method for the calendar grid. Be sure to add the declaration of Click to TSampleCalendar, including the override directive afterward.

Copy Code

    procedure TSampleCalendar.Click;
    var
      TempDay: Integer;
    begin
      inherited Click;                              { remember to call the inherited method! }
      TempDay := DayNum(Col, Row);                 { get the day number for the clicked cell }
      if TempDay <> -1 then Day := TempDay;                            { change day if valid }
    end;

Copy Code

    void __fastcall TSampleCalendar::Click()
    {
      int TempDay = DayNum(Col, Row);            // get the day number for the clicked cell
      if (TempDay != -1) Day = TempDay;          // change day if valid
    }

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!