Restricting a time bar from being added during a certain period
The method CancelDrop is used to prevent a user to add a new time bar or some a time bar being moved from one item into another. The CancelDrop method is only effective when used in the BarPreDrop event.
Example:
Private Sub ctSchedule1_BarPreDrop(ByVal nIndex As Integer, ByVal nBar As Integer, ByVal nStartDate As Long, ByVal nEndDate As Long, ByVal nStartTime As Long, ByVal nEndTime As Long, ByVal nRow As Integer, ByVal bNewApp As Boolean) |
If nStartTime >= 480 And nEndTime <= 1440 Then |
Me.ctSchedule1.CancelDrop |
End If |
End Sub |
Prevent a time bar from being added but allowing the current time bars to be moved or re-sized
This can be done by a combination of methods and events. You can create a global variable to be used as a flag. In the BarAdded event, check for the flag and if it is set to true then use ctSchedule Undo method.
Dim booAddFlag As Boolean 'Create a variable to act as a flag |
Private Sub ctSchedule1_BarAdded(ByVal nIndex As Integer, ByVal nBar As Integer, ByVal bMouseBar As Boolean, ByVal bKeyedBar As Boolean) |
If booAddFlag = False Then |
Me.ctSchedule1.Undo 'Perform the undo operation on ctSchedule |
End If |
End Sub |
Private Sub ctSchedule1_FirstDraw() |
Dim nIndex As Integer |
booAddFlag = True |
nIndex = Me.ctSchedule1.AddItem("Item 1") |
nIndex = Me.ctSchedule1.AddTimeBar(1, 20, 140, -1, -1) |
booAddFlag = False 'Once all the items are added, set the flag to false, so no more items can be added |
End Sub |
Preventing a time bar from being resized, but allowing a time bar to move
This can be done by a combination of methods and events. You can create a global variable to be used as a flag. In the mouse up event, check for the flag and if it is set to true then use ctSchedule Undo method.
Example:
Dim booReSizeFlag As Boolean 'Create a variable to act as a flag |
Private Sub ctSchedule1_BarSizing(ByVal nIndex As Integer, ByVal nBar As Integer, ByVal nType As Integer, ByVal lTimeStart As Long, ByVal lTimeEnd As Long, ByVal lDateStart As Long, ByVal lDateEnd As Long) |
If nType > 1 Then 'A value of 3 or 4 indicate that the start or end time is being changed. A value of 1 indicates that the bar is being moved, and a value of 0 indicates a new time bar |
booReSizeFlag = True |
End If |
End Sub |
Private Sub ctSchedule1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) |
If booReSizeFlag = True Then |
Me.ctSchedule1.Undo 'Perform an undo operation on the schedule. |
booReSizeFlag = False 'Reset the flag |
End If |
End Sub |