The ExG2Host is an extension of the ExG2antt ( Exontrol's Grid-Gantt component ) with full database support ( ADO, DAO, XML). In other words, the ExG2Host loads and saves automatically the host's data (including the hierarchy) to one or more databases. You can map a data field from the data-source, to a property of one object in the host/gantt control, and the control automatically updates the field when it is required.
The following VB sample displays a message box, before pressing the Delete key, and cancel the operation if user selects No or Cancel:
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
If (EventID = exHostKeyDown) Then
If (vbKeyDelete = CInt(G2Host1.HostEventParam(0))) Then
If Not (MsgBox("Do you want to delete?", vbYesNoCancel) = vbYes) Then
G2Host1.HostEventParam(0) = 0
End If
End If
End If
End Sub
You can disable completely deletion by removing the exHostAllowDelete
flag from the HostReadOnly property.
The ExG2Host is an extension of the ExG2antt ( Exontrol's Grid-Gantt component ) with full database support ( ADO, DAO, XML).
In other words, the ExG2Host loads and saves automatically the host's data (including the hierarchy) to one or more databases.
You can map a data field from the data-source, to a property of one object in the host/gantt control, and the control automatically updates the field when it is required.
Shortly, the ExG2Host uses the ExG2antt which means that if you buy ExG2Host library you automatically get the ExG2antt control as well.
By default, the control creates an instance of ExG2antt type, and the Host property returns a reference to the newly created host. Shortly, the Host property supports all methods and properties listed here. In order to get
the bar from the cursor, you have to use the BarFromPoint property of the Chart object.
The following VB sample sample just displays the bar's key as soon as the user clicks the control:
' HostEvent event - Notifies the application once the host fires an event.
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
If (EventID = exHostClick) Then ' Click
MsgBox G2Host1.Host.Chart.BarFromPoint(-1, -1)
End If
End Sub
The following MS Access sample sample just displays the bar's key as soon as the user clicks the control:
' HostEvent event - Notifies the application once the host fires an event.
Private Sub G2Host1_HostEvent(ByVal EventID As Long)
If (EventID = exHostClick) Then ' Click
MsgBox G2Host1.Host.Chart.BarFromPoint(-1, -1)
End If
End Sub
Shortly, you need to change the OLEDropMode property of the Host object, and handle the OLEStartDrag through the HostEvent event as in any of the following samples
The following VB sample starts OLE drag and drop as soon as user clicks and drags the item (for MS Access replace EXG2HOSTLibCtl.HostEventEnum with Long):
Private Sub Form_Load()
G2Host1.Host.OLEDropMode = 1
End Sub
' HostEvent event - Notifies the application once the host fires an event.
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
If EventID = 1002 Then ' event OLEStartDrag (Data as ExDataObject, AllowedEffects as Long)
G2Host1.HostEventParam(0).SetData ("some data to be dragged")
End If
End Sub
The following VB sample displays information about the OLE Drag and Drop events (for MS Access replace EXG2HOSTLibCtl.HostEventEnum with Long):
Private Sub Form_Load()
G2Host1.Host.OLEDropMode = 1
End Sub
' HostEvent event - Notifies the application once the host fires an event.
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
' displays information about OLE Drag and Drop events such as: OLEDragOver(1000), OLEDragDrop(1001), OLEStartDrag(1002), OLECompleteDrag(1003), OLEGiveFeedback(1004) and OLESetData(1005)
If (EventID >= 1000) And (EventID <= 1005) Then
Debug.Print G2Host1.HostEventParam(-2)
End If
If EventID = 1002 Then ' event OLEStartDrag (Data as ExDataObject, AllowedEffects as Long)
G2Host1.HostEventParam(0).SetData ("some data to be dragged")
End If
End Sub
that contains the name/identifier(parameters) of the inner event. For instance, "OLEDragDrop/1001( [Object] , =1 , 0 , 0 , 18 , 121 )" indicates the OLEDragDrop event, which IDentifier is 1001, and it has 6 parameters as follows:
During the HostEvent event, you can use the HostEventParam(Parameter) to access a parameter giving its index. For instance, HostEventParam(0) gets the first-parameter (Data of ExDataObject type), while HostEventParam(1) gets the second parameter (Effect of Long type), and so on.
In conclusion, the following VB sample decodes the OLE Drag and Drop events, including their parameters (for MS Access replace EXG2HOSTLibCtl.HostEventEnum with Long):
' HostEvent event - Notifies the application once the host fires an event.
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
With G2Host1
Dim o As EXG2ANTTLibCtl.ExDataObject
Select Case EventID
Case 1000 ' event OLEDragOver (Data as ExDataObject, Effect as Long, Button as Integer, Shift as Integer, X as OLE_XPOS_PIXELS, Y as OLE_YPOS_PIXELS, State as Integer)
Debug.Print "OLEDragOver"
Set o = .HostEventParam(0)
Debug.Print " Data: ", o.GetData(1)
Debug.Print " Effect: ", .HostEventParam(1)
Debug.Print " Button: ", .HostEventParam(2)
Debug.Print " Shift: ", .HostEventParam(3)
Debug.Print " X: ", .HostEventParam(4)
Debug.Print " Y: ", .HostEventParam(5)
Debug.Print " State: ", .HostEventParam(6)
Case 1001 ' event OLEDragDrop (Data as ExDataObject, Effect as Long, Button as Integer, Shift as Integer, X as OLE_XPOS_PIXELS, Y as OLE_YPOS_PIXELS)
Debug.Print "OLEDragDrop"
Set o = .HostEventParam(0)
Debug.Print " Data: ", o.GetData(1)
Debug.Print " Effect: ", .HostEventParam(1)
Debug.Print " Button: ", .HostEventParam(2)
Debug.Print " Shift: ", .HostEventParam(3)
Debug.Print " X: ", .HostEventParam(4)
Debug.Print " Y: ", .HostEventParam(5)
Case 1002 ' event OLEStartDrag (Data as ExDataObject, AllowedEffects as Long)
Debug.Print "OLEStartDrag"
Set o = .HostEventParam(0)
Debug.Print " Data: ", o.Files.Count
Debug.Print " AllowedEffects: ", .HostEventParam(1)
o.SetData ("some data to be dragged")
Case 1003 ' event OLECompleteDrag (Effect as Long)
Debug.Print "OLECompleteDrag"
Debug.Print " Effect: ", .HostEventParam(0)
Case 1004 ' event OLEGiveFeedback (Effect as Long, DefaultCursors as Boolean)
Debug.Print "OLEGiveFeedback"
Debug.Print " Effect: ", .HostEventParam(0)
Debug.Print " DefaultCursors: ", .HostEventParam(1)
Case 1005 ' event OLESetData (Data as ExDataObject, Format as Integer)
Debug.Print "OLESetData"
Set o = .HostEventParam(0)
Debug.Print " Data: ", o.Files.Count
Debug.Print " Format: ", .HostEventParam(1)
End Select
End With
End Sub
The solution is to handle the HostEvent and monitor the exHostOffsetChanged and exHostDateChange events for the host. Once any of these occur you should update the ScrollPos and Chart.FirstVisibleDate properties.
The following sample uses the Layout property to update these properties at once (see bellow for MS Access):
Dim iLayout As Long
Private Function getLayout(ByVal G As EXG2HOSTLibCtl.G2Host)
With G.Host
getLayout = "HScroll=" & .ScrollPos(False) & vbCrLf
getLayout = getLayout & "VScroll=" & .ScrollPos(True) & vbCrLf
getLayout = getLayout & "Chart.FirstVisibleDate=#" & .Chart.FirstVisibleDate & "#" & vbCrLf
End With
End Function
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
'Debug.Print G2Host1.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then G2Host2.Host.Layout = getLayout(G2Host1)
iLayout = iLayout - 1
End If
End Sub
Private Sub G2Host2_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
'Debug.Print G2Host2.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then G2Host1.Host.Layout = getLayout(G2Host2)
iLayout = iLayout - 1
End If
End Sub
Private Sub Form_Load()
iLayout = 0
End Sub
The iLayout variable ensures that no recursively call occurs. The sample uses the Layout property, which saves or restores the control's UI layout. The same could be done if you call the ScrollPos or Chart.FirstVisibleDate separately as follows:
Dim iLayout As Long
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
'Debug.Print G2Host1.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then
With G2Host2.Host
.ScrollPos(True) = G2Host1.Host.ScrollPos(True)
.ScrollPos(False) = G2Host1.Host.ScrollPos(False)
.Chart.FirstVisibleDate = G2Host1.Host.Chart.FirstVisibleDate
End With
End If
iLayout = iLayout - 1
End If
End Sub
Private Sub G2Host2_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
'Debug.Print G2Host2.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then
With G2Host1.Host
.ScrollPos(True) = G2Host2.Host.ScrollPos(True)
.ScrollPos(False) = G2Host2.Host.ScrollPos(False)
.Chart.FirstVisibleDate = G2Host2.Host.Chart.FirstVisibleDate
End With
End If
iLayout = iLayout - 1
End If
End Sub
The sample can be changed to syncronize the UI layout of both controls, as follows:
Dim iLayout As Long
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
'Debug.Print G2Host1.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange Or EventID = exHostChartEndChanging) Then
iLayout = iLayout + 1
If (iLayout = 1) Then G2Host2.Host.Layout = G2Host1.Host.Layout
iLayout = iLayout - 1
End If
End Sub
Private Sub G2Host2_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
'Debug.Print G2Host2.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange Or EventID = exHostChartEndChanging) Then
iLayout = iLayout + 1
If (iLayout = 1) Then G2Host1.Host.Layout = G2Host2.Host.Layout
iLayout = iLayout - 1
End If
End Sub
Private Sub Form_Load()
iLayout = 0
End Sub
The following sample uses the Layout property to update these properties at once (MS Access):
Dim iLayout As Long
Private Function getLayout(ByVal G As Object)
With G.Host
getLayout = "HScroll=" & .ScrollPos(False) & vbCrLf
getLayout = getLayout & "VScroll=" & .ScrollPos(True) & vbCrLf
getLayout = getLayout & "Chart.FirstVisibleDate=#" & .Chart.FirstVisibleDate & "#" & vbCrLf
End With
End Function
Private Sub G2Host1_HostEvent(ByVal EventID As Long)
'Debug.Print G2Host1.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then
With G2Host2.Host
.Layout = getLayout(G2Host1.Object)
End With
End If
iLayout = iLayout - 1
End If
End Sub
Private Sub G2Host2_HostEvent(ByVal EventID As Long)
'Debug.Print G2Host2.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then
With G2Host1.Host
.Layout = getLayout(G2Host2.Object)
End With
End If
iLayout = iLayout - 1
End If
End Sub
Private Sub Form_Load()
iLayout = 0
End Sub
The iLayout variable ensures that no recursively call occurs. The sample uses the Layout property, which saves or restores the control's UI layout. The same could be done if you call the ScrollPos or Chart.FirstVisibleDate separately as follows:
Dim iLayout As Long
Private Sub G2Host1_HostEvent(ByVal EventID As Long)
'Debug.Print G2Host1.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then
With G2Host2.Host
.ScrollPos(True) = G2Host1.Host.ScrollPos(True)
.ScrollPos(False) = G2Host1.Host.ScrollPos(False)
.Chart.FirstVisibleDate = G2Host1.Host.Chart.FirstVisibleDate
End With
End If
iLayout = iLayout - 1
End If
End Sub
Private Sub G2Host2_HostEvent(ByVal EventID As Long)
'Debug.Print G2Host2.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange) Then
iLayout = iLayout + 1
If (iLayout = 1) Then
With G2Host1.Host
.ScrollPos(True) = G2Host2.Host.ScrollPos(True)
.ScrollPos(False) = G2Host2.Host.ScrollPos(False)
.Chart.FirstVisibleDate = G2Host2.Host.Chart.FirstVisibleDate
End With
End If
iLayout = iLayout - 1
End If
End Sub
The sample can be changed to syncronize the UI layout of both controls, as follows:
Dim iLayout As Long
Private Sub G2Host1_HostEvent(ByVal EventID As Long)
'Debug.Print G2Host1.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange Or EventID = exHostChartEndChanging) Then
iLayout = iLayout + 1
If (iLayout = 1) Then G2Host2.Host.Layout = G2Host1.Host.Layout
iLayout = iLayout - 1
End If
End Sub
Private Sub G2Host1_Updated(Code As Integer)
End Sub
Private Sub G2Host2_HostEvent(ByVal EventID As Long)
'Debug.Print G2Host2.HostEventParam(-2) ' displays information about the event
If (EventID = exHostOffsetChanged Or EventID = exHostDateChange Or EventID = exHostChartEndChanging) Then
iLayout = iLayout + 1
If (iLayout = 1) Then G2Host1.Host.Layout = G2Host2.Host.Layout
iLayout = iLayout - 1
End If
End Sub
Private Sub Form_Load()
iLayout = 0
End Sub
The Layout property saves or loads the control's UI layout, such as positions of the columns, scroll position, filtering values.
The HostEvent(exHostCreateBar) event is fired once the user creates a new task. The HostEventParam(0) defines the item that hosts the newly created bar. The HostDef(exNewTaskID) property gets the identifier of the key being newly created. For instance, the following sample changes properties of the newly created bar such as exBarColor:
Private Sub G2Host1_HostEvent(ByVal EventID As Long)
If (EventID = exHostCreateBar) Then
'MsgBox G2Host1.HostEventParam(-2) ' displays information about the event
With G2Host1
Dim item As Long, key As Variant
item = .HostEventParam(0)
key = .HostDef(exNewTaskID)
.HostDef(exTaskName) = "Progress"
.Host.Items.AddBar item, .HostDef(exTaskName), .HostEventParam(1), .HostEventParam(2), key
.Host.Items.ItemBar(item, key, 33) = RGB(0, 255, 0) ' exBarColor(33)
End With
End If
End Sub
The sample changes the bar's color (green) and type(progress) once the user creates the bar by drag and drop. The bar's color and type is saved into the database only if the exTasksColor and exTasksName options of DataField property are set as in the next sample. By default, the control automatically creates the new bar (while Host.AllowCreateBar property is exCreateBarAuto) right after the HostEvent(exHostCreateBar) event. You can change this behavior by setting the Host.AllowCreateBar property to exCreateBarManual, and so you have to add the bar during the HostEvent(exHostCreateBar) event.
With G2Host1
.DataField(exTasksColor) = "Color"
.DataField(exTasksName) = "Name"
End With
The HostEvent(EventID) event occurs once the host-control (exg2antt) fires an event and before the control itself to handle the event. The HostEvent(-EventID) event (negative event) occurs once the host-control (exg2antt) fires an event and after the control itself handles the event (starting from version 19.0). Each event has different number of parameters, which is indicated by the HostEventParam(-1) property. Each parameter of the event can be accessed through the HostEventParam property. The HostEventParam(-2) gives a general information of the event. For instance, the HostEvent(-exHostCreateBar) event occurs once the user created the new-task by drag and drop. During the HostEvent(-exHostCreateBar) event you can access the newly created bar using the HostEventParam(0) that returns the handle of the item that hosts the item-bar, and HostDef(exNewTaskID) gets the key of the newly created bar.
Private Sub G2Host1_HostEvent(ByVal EventID As EXG2HOSTLibCtl.HostEventEnum)
If (EventID = -exHostCreateBar) Then
G2Host1.Host.Items.ItemBar(G2Host1.HostEventParam(0), G2Host1.HostDef(exNewTaskID), 33) = RGB(255, 0, 0)
End If
End Sub
The sample changes the color for the newly created bar.
The AutoSave property specifies the time in ms to perform saving, once the user changes the host. The Save method saves the control's data, while the HostDirty property is True. If no change occurs since last save, nothing will be saved.
Private Sub G2Host1_HostEvent(ByVal EventID As Long)
If (EventID = -exHostCreateBar) Then
With G2Host1
.Object.Save
MsgBox .Host.Items.ItemBar(0, "<*>", 256) & " " & .DataSource("Tasks").RecordCount
End With
End If
End Sub
The sample calls the Save method to update the changes into the associated recordset. Also, the sample displays the count of item-bars within the host and the records within the table that hosts the item-bars.