Esempio n. 1
0
        private void FillStructure()
        {
            _InFillStructure = true;
            if (!(_DataSource == null || string.IsNullOrEmpty(_ValueMember) || string.IsNullOrEmpty(_DisplayMember) || string.IsNullOrEmpty(_ParentLinkMember) || string.IsNullOrEmpty(_IsSelectableMember)))
            {
                this.BeginUpdate();
                this.Nodes.Clear();
                ValueIndex.Clear();
                CheckedNodes = new List <gTreeNode>();
                // TODO: Implement Sorting
                //_DataSource.DefaultView.Sort = _SortByMember;
                // ================================================
                foreach (var DataItem in _DataSource)
                {
                    Object parentLinkValue = DataItem.GetType().GetProperty(_ParentLinkMember).GetValue(DataItem, null);
                    if (parentLinkValue == null || Convert.ToInt32(parentLinkValue) == 0)
                    {
                        Font nodeFont = default(System.Drawing.Font);
                        if (!(bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null))
                        {
                            nodeFont = new System.Drawing.Font(this.Font, FontStyle.Italic);
                        }
                        else
                        {
                            nodeFont = new System.Drawing.Font(this.Font, FontStyle.Regular);
                        }
                        gTreeNode newNode = new gTreeNode(DataItem.GetType().GetProperty(_DisplayMember).GetValue(DataItem, null) as string,
                                                          DataItem.GetType().GetProperty(_ValueMember).GetValue(DataItem, null),
                                                          DataItem,
                                                          (bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null),
                                                          nodeFont);
                        this.Nodes.Add(newNode);

                        ValueIndex.Add(newNode.Key, newNode.FullPath);
                    }
                }
                bool NodesAdded = false;
                do
                {
                    NodesAdded = false;
                    foreach (var DataItem in _DataSource)
                    {
                        Object parentLinkValue = DataItem.GetType().GetProperty(_ParentLinkMember).GetValue(DataItem, null);
                        if (parentLinkValue != null &&
                            ValueIndex.ContainsKey(parentLinkValue))
                        {
                            Font nodeFont = default(System.Drawing.Font);
                            if (!(bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null))
                            {
                                nodeFont = new System.Drawing.Font(this.Font, FontStyle.Italic);
                            }
                            else
                            {
                                nodeFont = new System.Drawing.Font(this.Font, FontStyle.Regular);
                            }
                            gTreeNode newNode = new gTreeNode(DataItem.GetType().GetProperty(_DisplayMember).GetValue(DataItem, null) as string,
                                                              DataItem.GetType().GetProperty(_ValueMember).GetValue(DataItem, null),
                                                              DataItem,
                                                              (bool)DataItem.GetType().GetProperty(_IsSelectableMember).GetValue(DataItem, null),
                                                              nodeFont);
                            if (!ValueIndex.ContainsKey(newNode.Key))
                            {
                                FindGTreeNode(ValueIndex[DataItem.GetType().GetProperty(_ParentLinkMember).GetValue(DataItem, null)]).Nodes.Add(newNode);
                                ValueIndex.Add(newNode.Key, newNode.FullPath);
                                NodesAdded = true;
                            }
                        }
                    }
                } while (NodesAdded);
                this.EndUpdate();
            }
            else
            {
                this.Nodes.Clear();
            }
            this.SelectedNode = null;
            _InFillStructure  = false;
        }
Esempio n. 2
0
        private void gTreeView_AfterCheck(object sender, TreeViewEventArgs e)
        {
            try
            {
                if (e.Node.Checked)
                {
                    bool      found = false;
                    gTreeNode a     = null;
                    foreach (gTreeNode a_loopVariable in CheckedNodes)
                    {
                        a = a_loopVariable;
                        if (e.Node.FullPath == a.FullPath)
                        {
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        CheckedNodes.Add((gTreeNode)e.Node);
                    }
                }
                else
                {
                    int a = 0;
                    for (a = 0; a < CheckedNodes.Count; a++)
                    {
                        if (e.Node.FullPath == CheckedNodes[a].FullPath)
                        {
                            CheckedNodes.RemoveAt(a);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            if (e.Node.Checked)
            {
                try
                {
                    CheckedNodes.Add((gTreeNode)e.Node);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
            else
            {
                try
                {
                    CheckedNodes.Remove((gTreeNode)e.Node);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
        }