Error when double clicking on a task
Details
Date:5/13/2011 6:06:56 PM
Product:ActiveGanttVBN Gantt Chart / Scheduler Component
Framework:.Net Framework 4.0 / Visual Studio 2010
Version:2.8.4
User's Development Environment:Visual Basic .Net 2010
Subject:Getting an Error
Question

I recently downloaded your trial version, AGVBN_NET40_2_8_4D.zip. I think you have an amazing product and I would like to implement it for our scheduling system. I am using the trial license until I get the program running smoothly, then I plan to buy it. However I get an error and I’m wondering if you can help me out.

I have taken code from your car rental sample program and modified it so it can be used for our machine scheduling. The program was working great until I implemented the tooltip portion. The error happens when I follow these steps…

I’ve included the code modules affected, and the stack trace in the attachment. I can’t find where the error is created in my code.

Stack Trace:


System.ArgumentOutOfRangeException was unhandled
  Message=Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  Source=mscorlib
  ParamName=index
  StackTrace:
       at System.Collections.ArrayList.get_Item(Int32 index)
       at AGVBN.clsCollectionBase.m_oReturnArrayElement(Int32 r_lIndex)
       at AGVBN.clsMouseKeyboardEvents.mp_EO_TASKMOVEMENT(E_MOUSEKEYBOARDEVENTS yMouseKeyBoardEvent, Int32 X, Int32 Y)
...
Answer

Answer:

We do have a bug which has to be corrected, double and single clicks are both raising the event: ControlClick.

So there is no way of telling if the user is double clicking or just single clicking on the control. And it will be fixed in our next release (2.8.6).

Your code is:


    Private Sub ActiveGanttVBNCtl1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ActiveGanttVBNCtl1.MouseDoubleClick
        Select Case GetContext
            Case "Task"
                Timer1.Enabled = False
                Dim oTask As clsTask = ActiveGanttVBNCtl1.Tasks.Item(ActiveGanttVBNCtl1.SelectedTaskIndex)
                Dim oForm As New fJobReservation("Edit", Me, oTask)
                oForm.ShowDialog(Me)
                Me.ToolStripButtonRefreshAll.PerformClick()
        End Select
    End Sub

However you have to use events that start with Control because the event that you are using comes from the framework, not the control. It is far safer in any case to use a right click for this purpose, and mouse down, double clicks come after Mouse down, mouse move, mouse up operations. A fast double click can generate a move operation sometimes. And the whole error you are getting is being caused by the Control thinking that you are trying to move a task. In our demo:


    Private Sub ActiveGanttVBNCtl1_ControlMouseDown(ByVal sender As Object, ByVal e As AGVBN.MouseEventArgs) Handles ActiveGanttVBNCtl1.ControlMouseDown
        Select Case e.EventTarget
            ...
            Case E_EVENTTARGET.EVT_SELECTEDTASK, E_EVENTTARGET.EVT_TASK
                If e.Button = E_MOUSEBUTTONS.BTN_RIGHT Then
                    e.Cancel = True
                    mp_oEditTask = ActiveGanttVBNCtl1.Tasks.Item(ActiveGanttVBNCtl1.MathLib.GetTaskIndexByPosition(e.X, e.Y).ToString())
                    If mp_oEditTask.Tag = "0" Then
                        mnuConvertToRental.Visible = True
                    Else
                        mnuConvertToRental.Visible = False
                    End If
                    If mp_oEditTask.Tag = "2" Then
                        mnuEditTask.Visible = False
                        mnuTaskLine.Visible = False
                    Else
                        mnuEditTask.Visible = True
                        mnuTaskLine.Visible = True
                    End If
                    mnuTaskEdit.Show(ActiveGanttVBNCtl1, New System.Drawing.Point(e.X, e.Y))
                End If
        End Select
    End Sub

Please notice the line e.Cancel = true, it's telling the control to stop thinking that it is a move operation, without this code the control will think it's being moved.

If you have to use DoubleClick for some reason, another possibility would be for you to use the following code:


    Private Sub ActiveGanttVBNCtl1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ActiveGanttVBNCtl1.MouseDoubleClick
        Select Case GetContext
            Case "Task"
                ActiveGanttVBNCtl1.ObjectStateChangedEventArgs.Cancel = True
                Timer1.Enabled = False
                Dim oTask As clsTask = ActiveGanttVBNCtl1.Tasks.Item(ActiveGanttVBNCtl1.SelectedTaskIndex)
                Dim oForm As New fJobReservation("Edit", Me, oTask)
                oForm.ShowDialog(Me)
                Me.ToolStripButtonRefreshAll.PerformClick()
        End Select
    End Sub

Here the line: ActiveGanttVBNCtl1.ObjectStateChangedEventArgs.Cancel = True is very important because it tells the gantt chart control to interrupt all movement processing.

 

All trademarks are property of their respective holders, and are only used to directly describe the products and services being provided. Their use in no way indicates any relationship or endorsement between The Source Code Store LLC and the holders of said trademarks.