Rt-Click and Cut/paste |
Post Reply |
Author | |
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
Posted: 07 January 2007 at 1:07pm |
Is there a way to use a right-click to cut and then paste an appointment to another date/time?
|
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
You can handle standard mouse notifications and use CalendarControl.CalendarView.HitTest function to show popup menu. We do have a sample code in our examples of such implementation.
Then use CalendarControl.CalendarView.Cut/Copy/Paste methods. See also CanCut/CanCopy/CanPaste properties. -- WBR, Serge |
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Thanks for the info.
However, I am still stuggling with this.
I've used the code from:
If Not HitTest.ViewEvent Is Nothing Then
Set ContextEvent = HitTest.ViewEvent.Event Me.PopupMenu mnuContexEditEvent Set ContextEvent = Nothing ElseIf (HitTest.HitCode = xtpCalendarHitTestDayViewTimeScale) Then Me.PopupMenu mnuContextTimeScale Else Me.PopupMenu mnuContextNewEvent End If to have the popup show up. Added a 'cut appointment' to the menu as well as: mnuCutAppt_click
However, I am stuck there. tried a few things such as: CalendarControl.DayView.Cut ContextEvent
and CalendarControl.ActiveView.CanCut = True (error).
Please help!!!!! I am desperate. I have to show a prototype soon!
thanks!!!
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
Here's the instructions I use to make 'Cut/Copy/Paste' working:
select case Mode
Case "Cut" If Calendar.ActiveView.CanCut Then Calendar.ActiveView.Cut Case "Copy" If Calendar.ActiveView.CanCopy Then Calendar.ActiveView.Copy Case "Paste" If Calendar.ActiveView.CanPaste Then Calendar.ActiveView.Paste end select |
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
Also note that Cut/Copy/Paste work with selected events.
Add a validation whether selection is empty. If so, select a context event before calling Cut/Copy/Paste. -- WBR, Serge |
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Dentor- where did you place that code?
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Dentor- where did you place your code?
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
The code is place in response of the context (popup) menu:
Private Sub ContextMenu_Click(Index As Integer)
Select Case Index Case 0: ' Cut If Calendar.ActiveView.CanCut Then Calendar.ActiveView.Cut Case 1: ' Copy If Calendar.ActiveView.CanCopy Then Calendar.ActiveView.Copy Case 2: ' Paste If Calendar.ActiveView.CanPaste Then Calendar.ActiveView.Paste End Select End Sub As Serge said, to cut or copy an event, the event must be selected first.
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
To be sure an event is pointed and to select it automatically, you can also write:
Private Sub ContextMenu_Click(Index As Integer)
Dim HitTest As CalendarHitTestInfo
Set HitTest = Calendar.ActiveView.HitTest
Select Case Index
Case 0: ' Cut If Not HitTest.ViewEvent Is Nothing Then
HitTest.ViewEvent.Selected = True If Calendar.ActiveView.CanCut Then Calendar.ActiveView.Cut End If Case 1: ' Copy If Not HitTest.ViewEvent Is Nothing Then
HitTest.ViewEvent.Selected = True
If Calendar.ActiveView.CanCopy Then Calendar.ActiveView.Copy End If
Case 2: ' Paste If Calendar.ActiveView.CanPaste Then Calendar.ActiveView.Paste End Select End Sub |
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
I must be a little slow with this cold weather
I am new to this control, not a programmer by trade....
and
I am not having any luck... can you give a little more direction? suggestions?
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
Not so cold in France this week
I think you are searching the way to insert a context menu on Calendar control. You can use the ContextMenu event of Clendar Control
Private Sub Calendar_ContextMenu(ByVal X As Single, ByVal Y As Single)
Dim HitTest As CalendarHitTestInfo Set HitTest = Calendar.ActiveView.HitTest
If Not HitTest.ViewEvent Is Nothing Then ' *** Context Menu of existing event where you can place Cut/Copy/Paste an event ElseIf (HitTest.HitCode = xtpCalendarHitTestDayViewTimeScale) Then ' *** Context Menu of the Time Scale if any Else ' *** Context Menu of inserting a new event where you can place 'Paste an event' End If End Sub Hope this will help you.
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
I actually am ok with getting a pop-up menu to show up. Its just what do i do then?
I have a menu called mnuCutAppt and a procedure: mnuCutAppt_click
but from there, Im lost.....
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Dentor,
thanks so much for taking the time to put that together.
Actually, I was successful in create the pop-up menu itself.
I am stuck on what to do then.
My plan is to use this in a physician's office and I want my users to be able to cut/paste an appointment when the patient calls and reschedules.... does this make sense and is feasible?
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
Your project is perfectly feasible. You can put these three buttons (Cut/Copy/Paste) in a toolbar or in a popup menu (as in the sample program I send you in the precedent message).
To test the sample, you can insert an appointement, right-clic it, choose 'Cut', and then insert it anywhere else by right-clicking and choose 'Paste'.
Does the sample program works for you ?
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
the sample works fine, thanks again for that!!!
I am just really stumped by the steps after you click the 'Cut appointment"
in the sample I DL from CodeJock, I can't even seem to get the toolbar cut to work....
what am I missing?
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
As the method Calendar.ActiveView.Cut works with the selected appointment, you must be sure the appointment right-clicked is really selected.
So you get the lines of program that must be in the Sub 'ContextEdit_Click()' : (because HitTest property has a value only in this sub)
Private Sub ContextEdit_Click()
Dim HitTest As CalendarHitTestInfo Set HitTest = Calendar.ActiveView.HitTest If Not HitTest.ViewEvent Is Nothing Then
HitTest.ViewEvent.Selected = True End If End Sub After you click the 'Cut Appointment' menu :
Private Sub mnuCutAppt_Click()
If Calendar.ActiveView.CanCut Then Calendar.ActiveView.Cut End Sub Then you cut the appointment selected.
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Great, thanks!
How do you set: Calendar.ActiveView.Cut??
I've tried
Calendar.ActiveView.Cut = true in my code but got an error.
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
Calendar is the name of CalendarControl, and 'Cut' is a method, not a property, with no parameter, so the right instruction is:
Calendar.ActiveView.Cut
You can add the CanCut property (this property is true if you can Cut an appointment), that makes:
If Calendar.ActiveView.CanCut Then Calendar.ActiveView.Cut
This is the same with the 'Copy', or 'Paste' methods:
If Calendar.ActiveView.CanCopy Then Calendar.ActiveView.Copy
If Calendar.ActiveView.CanPaste Then Calendar.ActiveView.Paste
Good Week end
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
So, I am still missing something.
Here is what I have for CalendarControl_ContextMenu:
Private Sub CalendarControl_ContextMenu(ByVal x As Single, ByVal y As Single)
Debug.Print "On context menu"
Dim HitTest As CalendarHitTestInfo Set HitTest = CalendarControl.ActiveView.HitTest If Not HitTest.ViewEvent Is Nothing Then Set ContextEvent = HitTest.ViewEvent.Event Me.PopupMenu mnuContexEditEvent Set ContextEvent = Nothing ElseIf (HitTest.HitCode = xtpCalendarHitTestDayViewTimeScale) Then Me.PopupMenu mnuContextTimeScale Else Me.PopupMenu mnuContextNewEvent End If End Sub
as well as this:
Private Sub ContextEdit_Click()
Dim HitTest As CalendarHitTestInfo Set HitTest = CalendarControl.ActiveView.HitTest If Not HitTest.ViewEvent Is Nothing Then HitTest.ViewEvent.Selected = True End If End Sub then I have the menu named ContextMenu and the following:
Private Sub ContextMenu_Click(Index As Integer)
Select Case Index Case 0: ' Cut 'CalendarControl.ActiveView.CanCut 'If CalendarControl.ActiveView.CanCut Then CalendarControl.ActiveView.Cut Case 1: ' Copy If CalendarControl.ActiveView.CanCopy Then CalendarControl.ActiveView.Copy Case 2: ' Paste If CalendarControl.ActiveView.CanPaste Then CalendarControl.ActiveView.Paste End Select End Sub what am I still missing?????????
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello,
You are almost right, just one or two lines missing.
To this sub, I just add one line of code:
Private Sub CalendarControl_ContextMenu(ByVal x As Single, ByVal y As Single)
Debug.Print "On context menu" Dim HitTest As CalendarHitTestInfo Set HitTest = CalendarControl.ActiveView.HitTest If Not HitTest.ViewEvent Is Nothing Then HitTest.ViewEvent.Selected = True ' *** is missing Set ContextEvent = HitTest.ViewEvent.Event Me.PopupMenu mnuContexEditEvent Set ContextEvent = Nothing ElseIf (HitTest.HitCode = xtpCalendarHitTestDayViewTimeScale) Then Me.PopupMenu mnuContextTimeScale Else Me.PopupMenu mnuContextNewEvent End If End Sub This sub can be dropped (not necessary, because the code is already and must be, put in the CalendarControl_ContextMenu): Private Sub ContextEdit_Click() Dim HitTest As CalendarHitTestInfo Set HitTest = CalendarControl.ActiveView.HitTest If Not HitTest.ViewEvent Is Nothing Then HitTest.ViewEvent.Selected = True End If End Sub I correct just one case (0=Cut) of the select case:
Private Sub ContextMenu_Click(Index As Integer)
Select Case Index Case 0: ' Cut If CalendarControl.ActiveView.CanCut Then CalendarControl.ActiveView.Cut ' *** Corrected Case 1: ' Copy If CalendarControl.ActiveView.CanCopy Then CalendarControl.ActiveView.Copy Case 2: ' Paste If CalendarControl.ActiveView.CanPaste Then CalendarControl.ActiveView.Paste End Select End Sub Hope this will help you.
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Dentor,
Bingo!!! That did it! I am now able to cut appointments!
Thanks so much!
One other small item.... I seem to be able to now paste them but, no matter where I cut the appointment from and try to paste to (different resources, differet times) the appointment is showing up at the left upper most time, and not the time that I chose by right clicking....
help.......
|
|
dentor
Senior Member Joined: 30 November 2005 Location: France Status: Offline Points: 102 |
Post Options
Thanks(0)
|
Hello Dixie,
You're right, to paste an appointment at the right-clicked location, you must make sure the cell is selected.
So the sub 'CalendarControl_ContextMenu' must be modify to do the job:
(two lines added)
Private Sub CalendarControl_ContextMenu(ByVal x As Single, ByVal y As Single)
Debug.Print "On context menu" Dim HitTest As CalendarHitTestInfo Set HitTest = CalendarControl.ActiveView.HitTest If Not HitTest.ViewEvent Is Nothing Then HitTest.ViewEvent.Selected = True Set ContextEvent = HitTest.ViewEvent.Event Me.PopupMenu mnuContexEditEvent Set ContextEvent = Nothing ElseIf (HitTest.HitCode = xtpCalendarHitTestDayViewTimeScale) Then Me.PopupMenu mnuContextTimeScale Elseif HitTest.TimePartValid Then ' *** added to test location of cell clicked ' *** Make sure the cell right-clicked is selected CalendarControl.ActiveView.SetSelection HitTest.HitDateTime, DateAdd("n", Calendar.ActiveView.TimeScale, HitTest.HitDateTime), False Me.PopupMenu mnuContextNewEvent End If End Sub I think this solve the Paste case.
|
|
Dixie
Newbie Joined: 07 January 2007 Status: Offline Points: 12 |
Post Options
Thanks(0)
|
Dentor,
Once again, my thanks! This is exactly what I was looking for!
One small piece I forgot to mention- I am using a multi-resource schedule and so when I paste the appt, it shows up in the left most resources' column and not the one that was right-clicked.
Can you help?
|
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
1. Use latest demo from codejock. Buttons on toolbar work. NOTE 1. When you left-click on event -- subject editing is started. Buttons are disabled because no text is selected, otherwise Cut/Copy/Paste works with subject editor text (not with the event). NOTE 2. You can easily disable start subject editing by left-click. See menu Calendar->Advanced options. SetSelection function is outdated. Use CalendarView.Selection property. Just add string: CalendarControl.ActiveView.Selection.GroupIndex = HitTest.ViewGroup.GroupIndex Also, please look at calendar properties in object browser. -- WBR, Serge |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |