3
Answers

TreeView and ListBox - Values ?

John

John

14y
5k
1
Hi all

First timer here and a complete newbie heh..

I' jumped right in and are trying to learn C#, and i'v bin struggling whit a TreeView / ListBox solution the last couple of days and now i have to aske..  


This is how i Populate the Treeview:

 public void PopulateTreeView(string directoryValue, TreeNode parentNode)
        {
            try
            {
                DirectoryInfo directory = new DirectoryInfo(directoryValue);

                foreach (DirectoryInfo d in directory.GetDirectories())
                {
                    // Create Node
                    TreeNode t = new TreeNode(d.Name);

                    PopulateTreeView(d.FullName, t);
                    parentNode.Nodes.Add(t);
                }

                foreach (FileInfo f in directory.GetFiles("*.mp3"))
                {

                    TreeNode t = new TreeNode();
                    
                    t.Text = f.Name.ToString();
                    t.Tag = Path.GetFullPath(f.DirectoryName);

                    parentNode.Nodes.Add(t);
                }
            }
            catch (UnauthorizedAccessException)
            {
                parentNode.Nodes.Add("Access denied");
            }
        }

it's looking in a fixed directory (whit sub folders) for mp3 files.. this works.

now the big question from here..

I got a ListBox that has to become the playlist, sow i got button to add a selected TreeView Node over to ListBox
as you can see above i have a t.Text and a t.Tag, t.text holde the file name and t.Tag the FullPath

how do i get Text and FullPath into my ListBox as a Item ? i hav tryed DisplayMember and ValueMember :
            lbPlaylist.DisplayMember = tvMedia.SelectedNode.Text;
            lbPlaylist.ValueMember = Convert.ToString(tvMedia.SelectedNode.Tag);

lbPlaylist is the ListBox
can anyone of you help here ? 
is ther i a better way ?  
and please.. remember im a complete newbie :)

Answers (3)
0
Kirtan Patel

Kirtan Patel

NA 35k 2.8m 14y
'this' is Pointer not operator ..

by operator overloading mechanism you can overload operators only not the pointers



Here is list of operator that is over loadable ...

+ - * / % ^ & | ~
! , = < > <= >= ++ --
<< >> == != && || += -= /=
%= ^= &= |= *= <<= >>= [] ()
-> ->* new new[] delete delete[]