Print Page | Close Window

Rt-Click and Cut/paste

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Calendar
Forum Description: Topics Related to Codejock Calendar
URL: http://forum.codejock.com/forum_posts.asp?TID=6024
Printed Date: 26 September 2024 at 1:36pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Rt-Click and Cut/paste
Posted By: Dixie
Subject: Rt-Click and Cut/paste
Date 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?
 
 



Replies:
Posted By: sserge
Date Posted: 09 January 2007 at 1:34pm
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


Posted By: Dixie
Date Posted: 09 January 2007 at 9:20pm
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!!!


Posted By: dentor
Date Posted: 10 January 2007 at 3:38am
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
 
 


Posted By: sserge
Date Posted: 10 January 2007 at 4:31am
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


Posted By: Dixie
Date Posted: 10 January 2007 at 11:35am
Dentor- where did you place that code?
 
 


Posted By: Dixie
Date Posted: 10 January 2007 at 11:36am
Dentor- where did you place your code?


Posted By: dentor
Date Posted: 10 January 2007 at 12:37pm
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.
 


Posted By: dentor
Date Posted: 10 January 2007 at 1:06pm
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
 


Posted By: Dixie
Date Posted: 11 January 2007 at 8:50pm
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?
 


Posted By: dentor
Date Posted: 12 January 2007 at 12:29pm
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.
 


Posted By: Dixie
Date Posted: 12 January 2007 at 2:40pm
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.....


Posted By: dentor
Date Posted: 13 January 2007 at 2:58am
Hello,
 
Here is a sample of context menu 'Cut/Copy/Paste' :
 
https://forum.codejock.com/uploads/20070113_025528_Context.zip - uploads/20070113_025528_Context.zip
 
 


Posted By: Dixie
Date Posted: 13 January 2007 at 12:25pm
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? 


Posted By: dentor
Date Posted: 13 January 2007 at 1:03pm
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 ?
 


Posted By: Dixie
Date Posted: 13 January 2007 at 1:20pm
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?
 


Posted By: dentor
Date Posted: 13 January 2007 at 1:53pm
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.
 


Posted By: Dixie
Date Posted: 13 January 2007 at 2:09pm
Great, thanks!
 
How do you set: Calendar.ActiveView.Cut??
 
I've tried
Calendar.ActiveView.Cut = true in my code but got an error.
 


 


Posted By: dentor
Date Posted: 14 January 2007 at 3:19am
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
 


Posted By: Dixie
Date Posted: 14 January 2007 at 4:52pm
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?????????


Posted By: dentor
Date Posted: 15 January 2007 at 3:35am
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.
 


Posted By: Dixie
Date Posted: 15 January 2007 at 8:45am
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.......


Posted By: dentor
Date Posted: 16 January 2007 at 4:35am
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.
 


Posted By: Dixie
Date Posted: 17 January 2007 at 8:35am
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?


Posted By: sserge
Date Posted: 17 January 2007 at 6:04pm
Originally posted by Dixie Dixie wrote:

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?


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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net