Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. Im currently doing a project on magazine editor and I'm suppose to let the user edit the pages of some online magazine.

There will be a treeview which has parent nodes named, 'Page1, Page2' & so on and the child nodes will be, 'Video, Images, Podcast' depending on what the user choose. And the user will be able to upload the whatever he or she selected for example 'video/images/podcast' to the page. I understand that there is no way to save the whole treeview so I was suggested to use Arraylist to store the contents of the different pages.

As I'm new in vb.net, I've no idea how to create the class and the coding for arraylist for the treeview.

Can anyone help!!!!
Thanks a lot !!!!!
Posted
Comments
dan!sh 6-Apr-11 4:25am    
You want to save the treeview structure or the contents uploaded by the user?

There is not need to use ArrayList, ever. Instead, use generic System.Collection.Generic.List. Non-generic containers are rendered obsolete with introduction of generics in the .NET Framework 2.0.

—SA
 
Share this answer
 
Comments
Abhinav S 6-Apr-11 4:17am    
Good answer. 5. My answer below.
Sergey Alexandrovich Kryukov 6-Apr-11 4:22am    
Thank you, Abhinav. Your answer makes more sense, I explained in my comment to it.
--SA
Albin Abel 7-Apr-11 2:14am    
My 5. Let us keep it as a general suggestion somewhere that unless the collection has varying types, let it be always generic list.
Sergey Alexandrovich Kryukov 7-Apr-11 2:22am    
Thank you, Albin.
--SA
I would consider using a Dictionary object.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Apr-11 4:21am    
Agree, my 5. I admit I did not answer critically, just named the closest analog.
--SA
Abhinav S 6-Apr-11 4:52am    
I saw your other comment as well. Thank you.
Albin Abel 7-Apr-11 2:17am    
Good suggestion. Even a hierarchical dictionary works better for tree view. Then I think why not xml. It leads to think handling xml through a dataset would be easier in .net point of view. :). My 5
Abhinav S 7-Apr-11 2:20am    
Thank you, Albin.
You do not need ArrayList or anything to do a "save" of the treeview. You can have all the details in the TreeView object. For the actual save of the treeview structure (assuming you are saving that), you will need to have a database set up (depending on the application size) to map all the treeviews to the users.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Apr-11 15:34pm    
That is a good point. My 5.
--SA
Albin Abel 7-Apr-11 2:19am    
Good call. My 5
Assuming you have a class for your tree nodes similar to:
C#
[Serializable]
public class NodeBase : Base
    {
        NodeBase parent;
        string name;

        [Bindable(true)]
        [Browsable(true)]
        public NodeBase Parent
        {
            get
            {
                return parent;
            }
            set
            {
                if (parent == value)
                    return;
                parent = value;
                OnPropertyChanged("Parent");
            }
        }

        public NodeBase Self
        {
            get
            {
                return this;
            }
        }


        [Bindable(true)]
        [Browsable(true)]
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (name == value)
                    return;
                name = value;
                OnPropertyChanged("Name");
            }
        }
    }

It would be nice to be able to implement a component exposing the list in a way suitable for binding on a form
public class NodeList : BindingComponent<NodeBase>
    {
    }


Here is a simple implmentation of BindingComponent. You can the use something like
BinaryFormatter[^] to read and write the exposed BindingList.
public class BindingComponent<T> : Component,IBindingList, ITypedList
    {
        BindingList<T> items;
        
        public event ListChangedEventHandler ListChanged;
        public BindingComponent()
        {
            items = new BindingList<T>();
            items.ListChanged += items_ListChanged;
        }
        void items_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (ListChanged != null)
            {
                ListChanged(this, e);
            }
            
        }
        protected override void Dispose(bool disposing)
        {
            items.ListChanged -= items_ListChanged;
            base.Dispose(disposing);
        }

        [ListBindable(true)]
        [Bindable(true)]
        [Browsable(true)]
        public BindingList<T> Items
        {
            get
            {
                return items;
            }
        }

        public void AddIndex(PropertyDescriptor property)
        {
            ((IBindingList)Items).AddIndex(property);
        }
        public object AddNew()
        {
            return Items.AddNew();
        }
        public bool AllowEdit
        {
            get 
            {
                return Items.AllowEdit;
            }
        }
        public bool AllowNew
        {
            get 
            {
                return Items.AllowNew;
            }
        }
        public bool AllowRemove
        {
            get 
            {
                return Items.AllowRemove;
            }
        }
        public void ApplySort(PropertyDescriptor property, ListSortDirection direction)
        {
            ((IBindingList)Items).ApplySort(property, direction);
        }
        public int Find(PropertyDescriptor property, object key)
        {
            return ((IBindingList)Items).Find(property, key);
        }
        public bool IsSorted
        {
            get 
            {
                return ((IBindingList)Items).IsSorted;
            }
        }
        
        public void RemoveIndex(PropertyDescriptor property)
        {
            ((IBindingList)Items).RemoveIndex(property);
        }
        public void RemoveSort()
        {
            ((IBindingList)Items).RemoveSort();
        }
        public ListSortDirection SortDirection
        {
            get 
            {
                return ((IBindingList)Items).SortDirection;
            }
        }
        public PropertyDescriptor SortProperty
        {
            get 
            {
                return ((IBindingList)Items).SortProperty;
            }
        }
        public bool SupportsChangeNotification
        {
            get 
            {
                return ((IBindingList)Items).SupportsChangeNotification;
            }
        }
        public bool SupportsSearching
        {
            get 
            {
                return ((IBindingList)Items).SupportsSearching;
            }
        }
        public bool SupportsSorting
        {
            get 
            {
                return ((IBindingList)Items).SupportsSorting;
            }
        }
        public int Add(object value)
        {
            return ((IBindingList)Items).Add(value);
        }
        public void Clear()
        {
            ((IBindingList)Items).Clear();
        }
        public bool Contains(object value)
        {
            return ((IBindingList)Items).Contains(value);
        }
        public int IndexOf(object value)
        {
            return ((IBindingList)Items).IndexOf(value);
        }
        public void Insert(int index, object value)
        {
            ((IBindingList)Items).Insert(index, value);
        }
        public bool IsFixedSize
        {
            get 
            {
                return ((IBindingList)Items).IsFixedSize;
            }
        }
        public bool IsReadOnly
        {
            get 
            {
                return ((IBindingList)Items).IsReadOnly;
            }
        }
        public void Remove(object value)
        {
            ((IBindingList)Items).Remove(value);
        }
        public void RemoveAt(int index)
        {
            ((IBindingList)Items).RemoveAt(index);
        }
        public object this[int index]
        {
            get
            {
                return Items[index];
            }
            set
            {
                Items[index] = (T)value;
            }
        }
        public void CopyTo(Array array, int index)
        {
            ((IBindingList)Items).CopyTo(array, index);
        }
        public int Count
        {
            get 
            { 
                return items.Count; 
            }
        }
        public bool IsSynchronized
        {
            get 
            {
                return ((IBindingList)Items).IsSynchronized;
            }
        }
        public object SyncRoot
        {
            get 
            {
                return ((IBindingList)Items).SyncRoot;
            }
        }
        public System.Collections.IEnumerator GetEnumerator()
        {
            return ((IBindingList)Items).GetEnumerator();
        }
        private PropertyDescriptorCollection propertyDescriptorCollection;
        public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors)
        {
            if (propertyDescriptorCollection == null)
            {
                propertyDescriptorCollection = TypeDescriptor.GetProperties(typeof(T), new Attribute[] { new BrowsableAttribute(true) });
            }
            return propertyDescriptorCollection;
        }
        public string GetListName(PropertyDescriptor[] listAccessors)
        {
            return typeof(T).Name;
        }
        
    }


Regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Apr-11 0:54am    
Amazing effort, a 5.
--SA
Espen Harlinn 8-Apr-11 3:40am    
Thank you, SAKryukov!
Albin Abel 7-Apr-11 2:10am    
Great Effort. :) My 5
Espen Harlinn 8-Apr-11 3:41am    
Thank you, Albin Abel!
Abhinav S 7-Apr-11 2:20am    
Great answer. My 5.
If this does not help the OP, nothing will.

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