/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the top level object.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void SetTopLevelObject(object obj, IInspectorList list)
        {
            if (m_list != null)
            {
                m_list.BeginItemExpanding -= m_list_BeginItemExpanding;
                m_list.EndItemExpanding   -= m_list_EndItemExpanding;
            }

            m_list = list;
            m_list.Initialize(obj);
            gridInspector.List = m_list;

            m_list.BeginItemExpanding += m_list_BeginItemExpanding;
            m_list.EndItemExpanding   += m_list_EndItemExpanding;
        }
Exemple #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the top level object.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void SetTopLevelObject(object obj, IInspectorList list)
		{
			if (m_list != null)
			{
				m_list.BeginItemExpanding -= m_list_BeginItemExpanding;
				m_list.EndItemExpanding -= m_list_EndItemExpanding;
			}

			m_list = list;
			m_list.Initialize(obj);
			gridInspector.List = m_list;

			m_list.BeginItemExpanding += m_list_BeginItemExpanding;
			m_list.EndItemExpanding += m_list_EndItemExpanding;
		}
        ///// ------------------------------------------------------------------------------------
        ///// <summary>
        ///// Handles the KeyPress event of the tstxtSearch control.
        ///// </summary>
        ///// <param name="sender">The source of the event.</param>
        ///// <param name="e">The <see cref="System.Windows.Forms.KeyPressEventArgs"/> instance containing the event data.</param>
        ///// ------------------------------------------------------------------------------------
        //private void tstxtSearch_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    if (e.KeyChar != (char)Keys.Enter)
        //        return;

        //    Guid guid = new Guid(tstxtSearch.Text.Trim());
        //    int i = m_list.GotoGuid(guid);
        //    if (i >= 0)
        //    {
        //        gridInspector.RowCount = m_list.Count;
        //        gridInspector.Invalidate();
        //        gridInspector.CurrentCell = gridInspector[0, i];
        //    }
        //}

        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Refreshes the view.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void RefreshView()
        {
            // Get the object that's displayed in the first visible row of the grid.
            IInspectorObject firstDisplayedObj =
                m_list[gridInspector.FirstDisplayedScrollingRowIndex];

            // Get the current, selected row in the grid.
            IInspectorObject currSelectedObj = gridInspector.CurrentObject;

            if (currSelectedObj != null && WillObjDisappearOnRefresh != null)
            {
                // Check if the selected object will disappear after refreshing the grid.
                // If so, then save a reference to the selected object's parent object.
                if (WillObjDisappearOnRefresh(this, currSelectedObj))
                {
                    currSelectedObj = m_list.GetParent(gridInspector.CurrentCellAddress.Y);
                }
            }

            int keyFirstDisplayedObj = (firstDisplayedObj != null ? firstDisplayedObj.Key : -1);
            int keyCurrSelectedObj   = (currSelectedObj != null ? currSelectedObj.Key : -1);

            // Save all the expanded objects.
            List <int> expandedObjects = new List <int>();

            for (int i = 0; i < m_list.Count; i++)
            {
                if (m_list.IsExpanded(i))
                {
                    expandedObjects.Add(m_list[i].Key);
                }
            }

            m_list.Initialize(m_list.TopLevelObject);

            // Now that the list is rebuilt, go through the list of objects that
            // were previously expanded and expand them again.
            int firstRow = 0;
            int currRow  = 0;
            int irow     = 0;

            while (++irow < m_list.Count)
            {
                IInspectorObject io = m_list[irow];
                int key             = io.Key;
                int index           = expandedObjects.IndexOf(key);
                if (index >= 0)
                {
                    m_list.ExpandObject(irow);
                    expandedObjects.RemoveAt(index);
                }

                if (key == keyFirstDisplayedObj)
                {
                    firstRow = irow;
                }

                if (key == keyCurrSelectedObj)
                {
                    currRow = irow;
                }
            }

            gridInspector.SuspendLayout();
            gridInspector.List = m_list;
            gridInspector.FirstDisplayedScrollingRowIndex = firstRow;
            gridInspector.CurrentCell = gridInspector[0, currRow];
            gridInspector.ResumeLayout();
        }