Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. search or filter treenode display based on text input from user

search or filter treenode display based on text input from user

Scheduled Pinned Locked Moved Windows Forms
questioncsharpdatabasevisual-studiodata-structures
14 Posts 3 Posters 50 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U User 11025596

    Thanks but very few Winform samples in C# and none related to my question.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #5

    Are you saying you don't know how to handle text input, and use the content to change the focus of your TreeView?

    U 1 Reply Last reply
    0
    • L Lost User

      Member 11059799 wrote:

      If yes how is it done in VS C#?

      You'll have to WRITE it. And no, there's very little chance that anyone has done "exactly" what you need, so you search for an example that comes close and start there. Start here[^]

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      U Offline
      U Offline
      User 11025596
      wrote on last edited by
      #6

      Well that was no help at all. You think I didn't search for something close? I stepped through every one of those articles with tags VS, C#, and SQL. Not only is there nothing close but nothing near the planet and there isn't a Tag for Winforms. The project Social.Club might be useful but I can't get it to load and build per the instructions. Perhaps because I have VS 2013 and not VS 2010. Not sure. In any event it doesn't look like it contains an example of user text input to scroll the Tree display. Regards, Thom

      L 1 Reply Last reply
      0
      • L Lost User

        Are you saying you don't know how to handle text input, and use the content to change the focus of your TreeView?

        U Offline
        U Offline
        User 11025596
        wrote on last edited by
        #7

        Quote:

        Are you saying you don't know how to handle text input, and use the content to change the focus of your TreeView?

        As a newbie I'm not sure what your response means. I want the display to scroll based on user input in a textbox rather than using the scrollbar and mouse. If that's what you mean by your response, than yes, I don't know how.

        L 1 Reply Last reply
        0
        • U User 11025596

          Quote:

          Are you saying you don't know how to handle text input, and use the content to change the focus of your TreeView?

          As a newbie I'm not sure what your response means. I want the display to scroll based on user input in a textbox rather than using the scrollbar and mouse. If that's what you mean by your response, than yes, I don't know how.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #8

          I am still not sure what you are getting at. A textbox is used for text input, and your program can capture that text as it is entered or when it is complete. It then makes use of that text in whatever way necessary. Scrolling of a view is a separate issue and would require some code to be written to move a certain tree item to the top of the form (or area of the form). The suggestion at http://stackoverflow.com/questions/457932/c-sharp-how-do-i-scroll-selected-treeview-node-into-view[^] should help you to figure out how to ensure the selected node is visible.

          U 1 Reply Last reply
          0
          • L Lost User

            I am still not sure what you are getting at. A textbox is used for text input, and your program can capture that text as it is entered or when it is complete. It then makes use of that text in whatever way necessary. Scrolling of a view is a separate issue and would require some code to be written to move a certain tree item to the top of the form (or area of the form). The suggestion at http://stackoverflow.com/questions/457932/c-sharp-how-do-i-scroll-selected-treeview-node-into-view[^] should help you to figure out how to ensure the selected node is visible.

            U Offline
            U Offline
            User 11025596
            wrote on last edited by
            #9

            Okay. I got my answer from a respondent on MSDN. Since I'm in the process of learning the language, syntax, and nuances of Visual C# this is the kind of answer struggling people like me hope to receive from FORUMS like this. There is no way I would have known to do this or "Write It" without guidance.

            Quote:

            Hi Hawk73ku, According to your description, you'd like to find the specified treenode from the TreeView. I wrote a sample for you, Here are my steps. Step1: create a form with a textbox, a button and a treeview. Step2: set the button click event handler like this. List tnlist = new List();//collect the result nodes int count = -1;//used to record the index of the selectnode private void button1_Click(object sender, EventArgs e) { this.treeView1.Focus(); tnlist.Clear(); this.getallTreeNode(this.treeView1.Nodes, tnlist); if (tnlist != null && tnlist.Count > 0) { count++; if (count >= tnlist.Count) { count = 0; } this.treeView1.SelectedNode = tnlist[count]; } } private void getallTreeNode(TreeNodeCollection nodes, List ltn) { foreach (TreeNode tn in nodes) { if (tn.Text.ToLower().Contains(this.textBox1.Text.ToLower())) { ltn.Add(tn); } if (tn.Nodes.Count > 0) getallTreeNode(tn.Nodes, ltn); } } the getallTreeNode method in my code is used to collect the result treenodes to a list. Results: #TreeNode Class http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode(v=vs.110).aspx If you have any other concern regarding this issue, please feel free to let me know. Best regards, Youjun Tang

            L 1 Reply Last reply
            0
            • U User 11025596

              Okay. I got my answer from a respondent on MSDN. Since I'm in the process of learning the language, syntax, and nuances of Visual C# this is the kind of answer struggling people like me hope to receive from FORUMS like this. There is no way I would have known to do this or "Write It" without guidance.

              Quote:

              Hi Hawk73ku, According to your description, you'd like to find the specified treenode from the TreeView. I wrote a sample for you, Here are my steps. Step1: create a form with a textbox, a button and a treeview. Step2: set the button click event handler like this. List tnlist = new List();//collect the result nodes int count = -1;//used to record the index of the selectnode private void button1_Click(object sender, EventArgs e) { this.treeView1.Focus(); tnlist.Clear(); this.getallTreeNode(this.treeView1.Nodes, tnlist); if (tnlist != null && tnlist.Count > 0) { count++; if (count >= tnlist.Count) { count = 0; } this.treeView1.SelectedNode = tnlist[count]; } } private void getallTreeNode(TreeNodeCollection nodes, List ltn) { foreach (TreeNode tn in nodes) { if (tn.Text.ToLower().Contains(this.textBox1.Text.ToLower())) { ltn.Add(tn); } if (tn.Nodes.Count > 0) getallTreeNode(tn.Nodes, ltn); } } the getallTreeNode method in my code is used to collect the result treenodes to a list. Results: #TreeNode Class http://msdn.microsoft.com/en-us/library/system.windows.forms.treenode(v=vs.110).aspx If you have any other concern regarding this issue, please feel free to let me know. Best regards, Youjun Tang

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              Unfortunately you did not make it clear that you did not know the fundamentals of writing a WinForms application. Had you done so you would have received somewhat different responses. Although these forums are designed to help people with specific questions (see http://www.codeproject.com/Messages/3137519/Forum-Guidelines-PLEASE-READ.aspx[^]), rather than teach them how to program. If you want to learn from the beginning then there are many websites that offer beginners' tutorials, including here at CodeProject; but you are expected to go and find them for yourself.

              U 1 Reply Last reply
              0
              • L Lost User

                Unfortunately you did not make it clear that you did not know the fundamentals of writing a WinForms application. Had you done so you would have received somewhat different responses. Although these forums are designed to help people with specific questions (see http://www.codeproject.com/Messages/3137519/Forum-Guidelines-PLEASE-READ.aspx[^]), rather than teach them how to program. If you want to learn from the beginning then there are many websites that offer beginners' tutorials, including here at CodeProject; but you are expected to go and find them for yourself.

                U Offline
                U Offline
                User 11025596
                wrote on last edited by
                #11

                Pardon me. Had I known English wasn't understood here I would have made it painstakingly clear but thought my first sentence, "

                Quote:

                New to VS C# and inherited a partially developed C# Winform project. Need some guidance.

                said it all. Also I didn't see anywhere that you don't take kindly to folks learning. I'll make a note of that. But if my opening statement didn't work for you I would have thought an intelligent being such as yourself would have surmised my skill level based on the question. (go figure) It's very presumptuous of you to think I haven't gone through numerous tutorials and articles on the topic and while I've learned how to build the tree from a SQL source and update it, I did not find anything addressing my question and is why I came here hoping for some guidance. I'm so sorry I did that. I'll think twice about asking another. Have a good day. Thom

                L 1 Reply Last reply
                0
                • U User 11025596

                  Pardon me. Had I known English wasn't understood here I would have made it painstakingly clear but thought my first sentence, "

                  Quote:

                  New to VS C# and inherited a partially developed C# Winform project. Need some guidance.

                  said it all. Also I didn't see anywhere that you don't take kindly to folks learning. I'll make a note of that. But if my opening statement didn't work for you I would have thought an intelligent being such as yourself would have surmised my skill level based on the question. (go figure) It's very presumptuous of you to think I haven't gone through numerous tutorials and articles on the topic and while I've learned how to build the tree from a SQL source and update it, I did not find anything addressing my question and is why I came here hoping for some guidance. I'm so sorry I did that. I'll think twice about asking another. Have a good day. Thom

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  Member 11059799 wrote:

                  It's very presumptuous of you to think

                  I presumed nothing, but I can only base my responses on the information you provide. If it's not clear then I ask for clarification, which I did in several responses. If you can't understand my questions then you can do the same. I'm sorry that I could not provide all the information you wanted, but I did (I thought) make it clear on my part that I did not fully understand what you were asking for. And I'm sorry that you seem to think that you are not getting the value for money that is your due, but we do this in our own time and at no cost to you.

                  1 Reply Last reply
                  0
                  • U User 11025596

                    Well that was no help at all. You think I didn't search for something close? I stepped through every one of those articles with tags VS, C#, and SQL. Not only is there nothing close but nothing near the planet and there isn't a Tag for Winforms. The project Social.Club might be useful but I can't get it to load and build per the instructions. Perhaps because I have VS 2013 and not VS 2010. Not sure. In any event it doesn't look like it contains an example of user text input to scroll the Tree display. Regards, Thom

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #13

                    Member 11059799 wrote:

                    Not only is there nothing close but nothing near the planet

                    ..there's quite some examples out there on searching, also including WinForm-treeviews. Like I already said, we don't have examples on each scenario. Filtering would be harder to implement than searching; searching a single item and highlighting it would be a lot easier to start with.

                    1. Nodes.Find[^]
                    2. Looping all nodes yourself (recursively!) and checking it (will be harder if the tree lazyloads, and should ideally be done on the datasource, not the tree itself)

                    Member 11059799 wrote:

                    In any event it doesn't look like it contains an example of user text input to scroll the Tree display.

                    "Finding" an item in a tree requires a textbox for a search-term, and invoking the Find method. Highlighting that node should bring it into view. --edit; Simplest example I could come up with is given below. Do mind the difference between a node-key and its caption. Keynames should be unique, captions don't have to be. Anyting with more flexibility requires more coding.

                    using System;
                    using System.Collections.Generic;
                    using System.Linq;
                    using System.Threading.Tasks;
                    using System.Windows.Forms;

                    static class Program
                    {
                    static void Main()
                    {
                    using (var f = new Form())
                    {
                    var tb = new TextBox() { Dock = DockStyle.Top };
                    var tv = new TreeView() { Dock = DockStyle.Fill };
                    f.Controls.AddRange(new Control[] { tv, tb });

                            tv.Nodes.Add("one", "one").Nodes.Add("two", "two");
                            tv.Nodes.Add("three", "tree").Nodes.Add("nine", "nine");
                            tv.Nodes.Add("tree", "three").Nodes.Add("oak", "oak");
                    
                            tb.KeyDown += (o, a) =>
                                {
                                    a.Handled = a.KeyCode == Keys.Return;
                                    if (a.Handled)
                                    {
                                        TreeNode\[\] foundNodes = tv.Nodes.Find(tb.Text, true);
                                        if (foundNodes.Length > 0)
                                        {
                                            tv.SelectedNode = foundNodes\[0\];
                                            tv.Focus();
                    
                    1 Reply Last reply
                    0
                    • L Lost User

                      Member 11059799 wrote:

                      If yes how is it done in VS C#?

                      You'll have to WRITE it. And no, there's very little chance that anyone has done "exactly" what you need, so you search for an example that comes close and start there. Start here[^]

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                      E Offline
                      E Offline
                      Eric P Schneider
                      wrote on last edited by
                      #14

                      I would recreate a new tree-view and fill it with items found. Then switch the between the two different tree-view controls. lol, just noticed the date. Why do they have 14 year old threads on here..

                      Schneider

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups