Example #1
0
        public void RefreshTree()
        {
            if (m_TreeViewDataSource == null)
            {
                return;
            }

            if (m_Selection == null)
            {
                m_Selection = new int[0];
            }

            // get the names of the previous items
            var selected = m_Selection.Select(x => m_TreeViewDataSource.FindItem(x)).Where(t => t != null).Select(c => c.displayName).ToArray();

            // update the source
            m_TreeViewDataSource.UpdateData();

            // find the same items
            var reselected = m_TreeViewDataSource.GetRows().Where(x => selected.Contains(x.displayName)).Select(x => x.id).ToArray();

            if (!reselected.Any())
            {
                if (m_TreeViewDataSource.GetRows().Count > 0)
                {
                    reselected = new[] { m_TreeViewDataSource.GetItem(0).id };
                }
            }

            // update the selection
            OnItemSelectionChanged(reselected);
        }