X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fclass%2FManaged.Windows.Forms%2FSystem.Windows.Forms%2FListViewGroupCollection.cs;h=136a8a48e17469e92504dac01e2a98dd9090ee97;hb=e16285a739ad659b91c03616e4fe5078fa8cd0c8;hp=7dd31ac4242a03f425839923ff89c23ae6ecf918;hpb=7ede1af34ff22ab266c76cdadf4a4b40287a404d;p=mono.git diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewGroupCollection.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewGroupCollection.cs index 7dd31ac4242..136a8a48e17 100644 --- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewGroupCollection.cs +++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ListViewGroupCollection.cs @@ -41,15 +41,20 @@ namespace System.Windows.Forms { private List list = null; private ListView list_view_owner = null; + private ListViewGroup default_group; ListViewGroupCollection() { list = new List (); + + default_group = new ListViewGroup ("Default Group"); + default_group.IsDefault = true; } internal ListViewGroupCollection(ListView listViewOwner) : this() { list_view_owner = listViewOwner; + default_group.ListViewOwner = listViewOwner; } internal ListView ListViewOwner { @@ -102,9 +107,7 @@ namespace System.Windows.Forms if (Contains(value)) return -1; - CheckListViewItemsInGroup(value); - value.ListViewOwner = this.list_view_owner; - list.Add (value); + AddGroup (value); if (this.list_view_owner != null) list_view_owner.Redraw(true); @@ -228,55 +231,95 @@ namespace System.Windows.Forms if (list.Count <= index || index < 0) throw new ArgumentOutOfRangeException("index"); - if (!Contains(value)) { - CheckListViewItemsInGroup(value); - list[index] = value; - - if (list_view_owner != null) - list_view_owner.Redraw(true); - } + if (Contains (value)) + return; + + if (value != null) + CheckListViewItemsInGroup (value); + + list [index] = value; + + if (list_view_owner != null) + list_view_owner.Redraw(true); } } - public ListViewGroup this[string key] { + public ListViewGroup this [string key] { get { - foreach (ListViewGroup item in list) - { - if (item.Name.Equals(key)) - return item; - } + int idx = IndexOfKey (key); + if (idx != -1) + return this [idx]; return null; } set { - for(int i = 0; i < list.Count; i++) - { - if ((this[i].Name != null) && (this[i].Name.Equals(key))) { - this[i] = value; - break; - } - } + int idx = IndexOfKey (key); + if (idx == -1) + return; + + this [idx] = value; } } + int IndexOfKey (string key) + { + for (int i = 0; i < list.Count; i++) + if (list [i].Name == key) + return i; + + return -1; + } + #endregion public void AddRange(ListViewGroup[] groups) { - foreach (ListViewGroup item in groups) - { - Add(item); - } + foreach (ListViewGroup group in groups) + AddGroup (group); + + if (list_view_owner != null) + list_view_owner.Redraw (true); } public void AddRange(ListViewGroupCollection groups) { - foreach (ListViewGroup item in groups) - { - Add(item); + foreach (ListViewGroup group in groups) + AddGroup (group); + + if (list_view_owner != null) + list_view_owner.Redraw (true); + } + + internal ListViewGroup GetInternalGroup (int index) + { + if (index == 0) + return default_group; + + return list [index - 1]; + } + + internal int InternalCount { + get { + return list.Count + 1; } } + internal ListViewGroup DefaultGroup { + get { + return default_group; + } + } + + void AddGroup (ListViewGroup group) + { + if (Contains (group)) + return; + + CheckListViewItemsInGroup (group); + group.ListViewOwner = list_view_owner; + list.Add (group); + } + private void CheckListViewItemsInGroup(ListViewGroup value) { //check for correct ListView