Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I try to set focus TreeViewNode based on TextBox.Text (with dont care uppercase, lowercase) then no result.

For Excample Node Tag is "C:\7143\Baltek")

if I enter "C:\7143\baltek") or "C:\7143\BalteK") no result, because of Upper LowerCase typing

how can I adjust to find not with any type textbox.text.

What I have tried:

VB
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        
        'Expand(TextBox3.Text) '("C:\7143\Baltek")
        gotNode = False
        For Each n As TreeNode In Me.TreeView1.Nodes
            If Not gotNode Then
                
                selectTreeNode(n, TextBox3.Text) ' "C:\7143\Baltek")

                
            End If
          
        Next

    End Sub
Posted
Updated 21-Mar-19 22:14pm
Comments
Maciej Los 22-Mar-19 3:55am    
Show us your selectTreeNode method.

1 solution

I'd suggest to start with this: Comparing Strings in .NET | Microsoft Docs[^]

If you want to ignore case, check this: String.Equals Method (System) | Microsoft Docs[^]

VB.NET
Dim node2find = Me.TreeView1.Nodes.Cast(Of TreeNode)() _
	.Where(Function(n) n.Text.Equals(TextBox3.Text, StringComparison.InvariantCultureIgnoreCase)) _
	.ToList()


Above code will return a list of nodes which text equals to TextBox3.Text ignoring case.

[EDIT]
In case you want to compare a part of text, you need to use of of the following string functions:
StartsWith
Contains
EndsWith
Please, follow the first link (on the top of my answer).
 
Share this answer
 
v4
Comments
Nicomendox 22-Mar-19 10:41am    
I am sorry but I couldnt work with this code. but same problem here

Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
For Each n As TreeNode In Me.TreeView1.Nodes(0).Nodes
If n.Text = "Users" Then
TreeView1.SelectedNode = n
TreeView1.Select()
TreeView1.SelectedNode.Expand()

End If
Next
End Sub


When Type "Users" 'With Capital "U"
TreeView.SelectedNode is Focus On "C:\Users"
But When I type "users" with "u"
this time result is nothing.

is the problem about TreeView or about the Code ?
Maciej Los 22-Mar-19 10:51am    
You've stated that:
Hide   Copy Code
SelectredNode is "C:\Users"

If n.Text = "Users" Then

and my question is:
Does "C:\Users" is equal to "Users"?

See updated answer.
Nicomendox 22-Mar-19 14:17pm    
Absolutely "C:\Users" is same with "Users"

"C:\Users" is Tag and "Users" is Node under the Treeview.

My problem is if I type "C:\users" instade of "C:\Users" code dosent work. because not all letters match with the search string.

Under TreeView, Node Name is "Users" not "users. Problem is "u" and "U" difrencence.
Maciej Los 22-Mar-19 15:42pm    
Absolutely not! Check on this:
Dim s1 As String = "C:\Users"
Dim s2 As String = "users"

Console.WriteLine("Does '{0}' is equal to '{1}' = {2}", s1, s2, s1=s2)


And this:
Console.WriteLine("Does '{0}' constains '{1}' = {2}", s1, s2, s1.ToLower().Contains(s2.ToLower()))


;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900