Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tree View Deleting Problem

Status
Not open for further replies.

ferozy

Programmer
Feb 25, 2003
20
FJ
Hi,

I have problem in deleting from TreeView.

The treeview in my application loads the position and reportsTo from database.
That is the treeview will have
General Manager
Sales Manager
Sales Assistant
Human Resource Manager
IT Manager

Now when one needs to delete a position all they do is select from the treeview,
e.g ITManager and click the delete button.

Now if the user tries to Delete Sales Manager it should give an error message that the Position
linked to Sales Manager, That is the Sales Assistant has to be deleted first.
And the same goes for deleting General Manager, the rest has to be deleted first.

Below is the Function :

Public Function DeletePosition() As Boolean
Dim cnn As cls_Sys_DB
Dim bExecuteOK As Boolean
Dim iPositionID As Integer

DeletePosition = False

Set cnn = New cls_Sys_DB

With frmMainForm.TreeView1.SelectedItem
iPositionID = Right(.Key, Len(.Key) - 4)
End With
cnn.Query = "delete from position where " & _
"position_id=" & iPositionID

bExecuteOK = cnn.Execute(False)
DeletePosition = bExecuteOK
If bExecuteOK Then
MsgBox "Position deleted successfully."
Else
MsgBox "Error in deleting positon.Please try again."
End If
Set cnn = Nothing
End Function
 

If I understand you right something like this should work
[tt]
If frmMainForm.TreeView1.SelectedItem.Children > 0 Then
MsgBox "Your Error Message"
'your error code
End If
[/tt]

Good Luck

 
Thanks for your help it is working fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top