Click here to Skip to main content
15,892,737 members
Home / Discussions / C#
   

C#

 
Questiontreenodecollection nodes not working as expected with created class [SOLVED] Pin
tonyonlinux17-Feb-10 20:07
tonyonlinux17-Feb-10 20:07 
AnswerRe: treenodecollection nodes not working as expected with created class Pin
Dan Mos17-Feb-10 20:28
Dan Mos17-Feb-10 20:28 
GeneralRe: treenodecollection nodes not working as expected with created class [SOLVED] Pin
tonyonlinux18-Feb-10 1:07
tonyonlinux18-Feb-10 1:07 
GeneralRe: treenodecollection nodes not working as expected with created class Pin
tonyonlinux18-Feb-10 1:31
tonyonlinux18-Feb-10 1:31 
GeneralRe: treenodecollection nodes not working as expected with created class Pin
Dan Mos18-Feb-10 2:40
Dan Mos18-Feb-10 2:40 
GeneralRe: treenodecollection nodes not working as expected with created class Pin
tonyonlinux18-Feb-10 6:43
tonyonlinux18-Feb-10 6:43 
GeneralRe: treenodecollection nodes not working as expected with created class Pin
Dan Mos18-Feb-10 10:03
Dan Mos18-Feb-10 10:03 
GeneralRe: treenodecollection nodes not working as expected with created class Pin
tonyonlinux18-Feb-10 13:18
tonyonlinux18-Feb-10 13:18 
here is what I've come up with so far. 208 nodes get put into the array i checked that in the debugger but i get an exception each time it finds a instance where the node is the same. in example
says can not add or insert the item 'tbone,eater' in more than one place.

here is what i'm using in my main form
private void Filter_combo_SelectedIndexChanged(object sender, EventArgs e)
       {
           /* Populate the tree based on whatever the user selects to filter by
            * for example if they click on keywords then only show the keywords
            */

           string filter = Filter_combo.Text;





           using (var db = new mombooksDataContext(Properties.Settings.Default.BooksConnectionString2))
           {

               TreeNodeCollection[] nodes = new TreeNodeCollection[treeView1.Nodes.Count];
               treeView1.Nodes.CopyTo(nodes, 0);
               treeView1.Nodes.Clear();//get rid of this BEFORE we're done.
               treeView1.Nodes.AddRange(NodeBuilder.BuildNodes(treeView1.Nodes, db.Authors, db.Books, filter));

           }
       }


then i'm calling the modified class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using momdb;

namespace Utilties
{
    public sealed class NodeBuilder
    {
        // public static void BuildNodes(TreeNodeCollection nodes,IEnumerable<Author>authors, IEnumerable<Book> books, string filter)
         public static TreeNode[] BuildNodes(TreeNodeCollection nodes,IEnumerable<Author>authors,IEnumerable<Book>books,string filter)
       {
            TreeNode node = new TreeNode();
           
            if (filter == "Keywords")
              {
                  node = nodes.Add("Keywords");
                
                  books.ToList().ForEach(m =>
                    {
                        node.Nodes.Add(m.Keywords);
                        node.Tag = filter;
                        
                        
                    });
               
            }
            if (filter == "Title")
            {
                node = nodes.Add("Title");
                books.ToList().ForEach(m =>
                    {
                        node.Nodes.Add(m.Title);
                        node.Tag = filter;
                    });
            }
           if (filter =="Author")
           {
               node = nodes.Add("Authors");
               authors = authors.ToList().Distinct();
               authors.ToList().ForEach(m =>
                {
                 node.Nodes.Add(string.Format("{0},{1}",m.AuthorFirst,m.AuthorLast));

                    //node.Nodes.Add("testing");
                    
                    node.Tag=filter;
                
                 }); 
           }
           TreeNode[] holder = new TreeNode[node.Nodes.Count];
           for (int i = 0; i < node.Nodes.Count; i++)
           {

               holder[i] = node.Nodes[i];
           }

           return holder;
        }
      
    }
}


still confused Frown | :( Confused | :confused:
GeneralRe: treenodecollection nodes not working as expected with created class Pin
Dan Mos18-Feb-10 13:34
Dan Mos18-Feb-10 13:34 
GeneralRe: treenodecollection nodes not working as expected with created class Pin
tonyonlinux19-Feb-10 17:00
tonyonlinux19-Feb-10 17:00 
QuestionHow to set a property in a collection based on the join? Pin
sri_346417-Feb-10 20:04
sri_346417-Feb-10 20:04 
AnswerRe: How to set a property in a collection based on the join? Pin
Dan Mos17-Feb-10 20:36
Dan Mos17-Feb-10 20:36 
QuestionSaving Data on a Form Pin
thomas_anderson17-Feb-10 18:00
thomas_anderson17-Feb-10 18:00 
AnswerRe: Saving Data on a Form Pin
AspDotNetDev17-Feb-10 18:33
protectorAspDotNetDev17-Feb-10 18:33 
GeneralRe: Saving Data on a Form Pin
thomas_anderson17-Feb-10 20:23
thomas_anderson17-Feb-10 20:23 
GeneralRe: Saving Data on a Form Pin
Richard MacCutchan17-Feb-10 21:46
mveRichard MacCutchan17-Feb-10 21:46 
GeneralRe: Saving Data on a Form Pin
thomas_anderson20-Feb-10 11:28
thomas_anderson20-Feb-10 11:28 
GeneralRe: Saving Data on a Form Pin
AspDotNetDev17-Feb-10 21:47
protectorAspDotNetDev17-Feb-10 21:47 
GeneralRe: Saving Data on a Form Pin
thomas_anderson20-Feb-10 11:29
thomas_anderson20-Feb-10 11:29 
QuestionReading from parallel port using c# Pin
A k ch17-Feb-10 17:41
A k ch17-Feb-10 17:41 
Questionplease forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 15:20
tonyonlinux17-Feb-10 15:20 
AnswerRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
Dan Mos17-Feb-10 15:30
Dan Mos17-Feb-10 15:30 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 15:35
tonyonlinux17-Feb-10 15:35 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
Dan Mos17-Feb-10 15:37
Dan Mos17-Feb-10 15:37 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 15:54
tonyonlinux17-Feb-10 15:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.