Ejemplo n.º 1
0
        public static ListViewItem2[] CreateTree(IEnumerable <XElement> xElements, ListViewItem2 lviParent, bool skipEmpty)
        {
            var lvItems = new List <ListViewItem2>();

            foreach (XElement xe in xElements)
            {
                if (skipEmpty && xe.Attributes().All(xa => string.IsNullOrEmpty(xa.Value)))
                {
                    continue;
                }

                var subItems = xe.Attributes().Select(xa => xa.Value).ToArray();
                var lvi      = new ListViewItem2(subItems, lviParent)
                {
                    ForeColor = RandomColor.Next(), ImageIndex = 0
                };
                lvItems.Add(lvi);

                if (xe.Elements().Count() > 0)
                {
                    var lvis = CreateTree(xe.Elements(), lvi, true);
                    if (lvis.Length > 0)
                    {
                        lvi.AddChildren(lvis);
                    }
                }
            }

            return(lvItems.ToArray());
        }
Ejemplo n.º 2
0
        private static ListViewItem2[] GenerateFileSystemItems(string dirPath, ListViewItem2 lviParent)
        {
            var fseItems = new List <ListViewItem2>();

            var subDirs = Directory.GetDirectories(dirPath);

            foreach (var d in subDirs)
            {
                var di       = new DirectoryInfo(d);
                var subItems = new[] { di.Name, di.Extension, di.CreationTime.ToLongDateString(), di.LastAccessTime.ToLongDateString() };

                var lvi = new ListViewItem2(subItems, lviParent)
                {
                    ForeColor = RandomColor.Next(), ImageIndex = 0
                };

                var lviFSItems = GenerateFileSystemItems(d, lvi);
                if (lviFSItems != null && lviFSItems.Length > 0)
                {
                    lvi.AddChildren(lviFSItems);
                    // TreeListView.AssignParent(lvi, lviParent);
                }

                fseItems.Add(lvi);
            }

            var lviFiles = GetFileItems(dirPath, lviParent);

            fseItems.AddRange(lviFiles);
            return(fseItems.ToArray());
        }
Ejemplo n.º 3
0
        private static ListViewItem2[] PrepareTree(IList <XElement> xList, ListViewItem2 lviParent)
        {
            var lItems = new List <ListViewItem2>();

            for (int i = 0; i < xList.Count; ++i)
            {
                if (string.Compare(Names.ExpenseItem, xList[i].Name.LocalName) == 0)
                {
                    var li = GetListViewItem2(xList[i], lviParent);
                    li.ImageIndex = 0;
                    li.ForeColor  = RandomColor.Next();

                    lItems.Add(li);
                }
                else if (string.Compare(Names.ExpenseGroup, xList[i].Name.LocalName) == 0)
                {
                    var xaName = xList[i].Attribute(Names.Name);
                    var xaDate = xList[i].Attribute(Names.Date);

                    var subItems = new[] {
                        xaDate != null ? xaDate.Value : "?",
                        xaName != null ? xaName.Value : "Expense Group"
                    };

                    var xGroup = new ListViewItem2(subItems, null)
                    {
                        ImageIndex = 1,
                        ForeColor  = RandomColor.Next()
                    };

                    var xItems   = new List <XElement>(xList[i].Elements(XName.Get(Names.ExpenseItem)));
                    var lviItems = new ListViewItem2[xItems.Count];

                    for (int k = 0; k < xItems.Count; ++k)
                    {
                        var li = GetListViewItem2(xItems[k], xGroup);
                        li.ImageIndex = 0;
                        li.ForeColor  = RandomColor.Next();
                        lviItems[k]   = li;
                    }

                    xGroup.AddChildren(lviItems);

                    lItems.Add(xGroup);
                }
                else if (string.Compare(Names.Seperator, xList[i].Name.LocalName) == 0)
                {
                    lItems.Add(new ListViewItem2(null, null));
                }
                else
                {
                    continue;
                }
            }

            return(lItems.ToArray());
        }
Ejemplo n.º 4
0
 private void randomizeColorBtn_Click(object sender, EventArgs e)
 {
     try
     {
         foreach (ListViewItem lvi in listView.Items)
         {
             lvi.ForeColor = RandomColor.Next();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 5
0
        private static ListViewItem2[] GetFileItems(string dirPath, ListViewItem2 lviParent)
        {
            var fseItems = new List <ListViewItem2>();

            string[] files = Directory.GetFiles(dirPath);
            foreach (string f in files)
            {
                var fi       = new FileInfo(f);
                var subItems = new[] { fi.Name, fi.Extension, fi.Length.ToString(), fi.CreationTime.ToLongDateString() };

                var lvi = new ListViewItem2(subItems, lviParent)
                {
                    ForeColor = RandomColor.Next(), ImageIndex = 1
                };
                // TreeListView.AssignParent(lvi, lviParent);

                fseItems.Add(lvi);
            }

            return(fseItems.ToArray());
        }