Esempio n. 1
0
        protected void SelectNode(IRow key)
        {
            if (_findingKey || (_link.DataSet.State == DataSetState.Insert) || ((SelectedNode != null) && ((DBTreeNode)SelectedNode).KeyEquals(key)))
            {
                return;
            }

            _dataSettingSelected = true;
            try
            {
                // Given a key value, build only that portion of the tree required to discover the location of the node
                DBTreeNode node = FindNode(key);
                if (node != null)
                {
                    SelectedNode = node;
                }
                else
                {
                    ArrayList path = new ArrayList();
                    BuildParentPath((IRow)key.Copy(), path);
                    try
                    {
                        BeginUpdate();
                        try
                        {
                            for (int index = path.Count - 1; index >= 0; index--)
                            {
                                if (index == path.Count - 1)
                                {
                                    node = FindChild((IRow)path[index]);
                                    if ((node == null) && !_selecting)
                                    {
                                        UpdateTree();
                                        _selecting = true;
                                        try
                                        {
                                            SelectNode(key);
                                        }
                                        finally
                                        {
                                            _selecting = false;
                                        }
                                        return;
                                    }
                                }
                                else
                                {
                                    node = node.FindChild((IRow)path[index]);
                                }

                                if (node == null)
                                {
                                    throw new ControlsException(ControlsException.Codes.TreeViewUnconnected);
                                }

                                if (index == 0)
                                {
                                    SelectedNode = node;
                                }
                                else
                                {
                                    node.BuildChildren();
                                }
                            }
                        }
                        finally
                        {
                            EndUpdate();
                        }
                    }
                    finally
                    {
                        for (int index = 0; index < path.Count; index++)
                        {
                            ((IRow)path[index]).Dispose();
                        }
                    }
                }
            }
            finally
            {
                _dataSettingSelected = false;
            }
        }