Type | Description | |||
Boolean | A boolean expression that indicates whether the control detects when a record is deleted from the bounded recordset. |
By default, the DetectDelete property is False. The property has effect only if the DataSource property points to an ADO recordset ( /COM ). If the DetectDelete property is True, the control is notified when a record is deleted, and the associated item is removed from the control's items collection.
Handling the Delete method in the control, using the DAO recordset on MS Access
Private Sub Form_Load() With G2antt1 .BeginUpdate .DataSource = CurrentDb.OpenRecordset("Employees") .DetectDelete = True .EndUpdate End With End Sub
The code binds the control to a DAO recordset. The DetectDelete property on True, makes the control to move the current record on the item to be deleted, and to remove any reference to the record to be deleted.
Private Sub cmdRemove_Click() With G2antt1.Items .RemoveItem .FocusItem End With End SubThe code removes the focused item. The Items.RemoveItem call makes the control to fire the RemoveItem event, which will actually delete the associated record in the database, as in the following code
Private Sub G2antt1_RemoveItem(ByVal Item As Long) With G2antt1 If .DetectDelete Then With .DataSource .Delete End With End If End With End Sub
The code deletes the current record.
Handling the Delete method in the control, using the ADO recordset in VB
Private Sub Form_Load() With G2antt1 Set rs = CreateObject("ADOR.Recordset") With rs .Open "Employees", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\sample.accdb", 3, 3 End With .DataSource = rs .DetectDelete = True End With End Sub
The code binds the control to an ADO recordset.
Private Sub cmdRemove_Click() With G2antt1.DataSource .Delete End With End SubThe Delete method of the recordset removes the current record ( select a new item to the control, and the current record is changed ), and due DetectDelete the associated item is removed from the view.