I have a WinForm tree view (property is named "tvwAcct") where I would like to be able to search through all the existing nodes with a given string ("txtName.Text"), and if it already exists, to give the user a Message box warning to stop duplicate entries. It needs to be able to search all parent nodes and also child nodes. My current tree structure is as follows:
Bank account name
-> Sub-account name 1
-> Sub-account name 2
-> Sub-account name 3
Private Sub txtName_Validating(eventSender As Object, eventArgs As CancelEventArgs) Handles txtName.Validating
Dim Cancel As Boolean = eventArgs.Cancel
Dim b As Boolean = True
' [ other 'if' conditions here ]
ElseIf (tvwAcct.Nodes.Find(txtName.Text, b) Then
MyMsgBox("Sorry, this account name already exists. Please try again with a different name.", MsgBoxStyle.Information)
Cancel = True
Value of type TreeNode() cannot be converted to 'Boolean'.
The TreeView.Nodes.Find function returns an array of nodes, not a true / false value.
Try it like this:
ElseIf tvwAcct.Nodes.Find(txtName.Text, b).Length > 0 Then