private void InitializeAccessors()
        {
            var gridViewAccessor = new FieldAccessor(this, "gridView");
            reflectedGridView = gridViewAccessor.Get();
            var gridViewType = reflectedGridView.GetType();

            allGridEntriesAccessor = new FieldAccessor(reflectedGridView, "allGridEntries");
            topLevelGridEntriesAccessor = new FieldAccessor(reflectedGridView, "topLevelGridEntries");
            totalPropsAccessor = new FieldAccessor(reflectedGridView, "totalProps");
            selectedRowAccessor = new FieldAccessor(reflectedGridView, "selectedRow");

            setScrollOffsetAccessor = new MethodAccessor(gridViewType, "SetScrollOffset");
            refreshAccessor = new MethodAccessor(gridViewType, "Refresh");

            selectedGridEntryAccessor = new PropertyAccessor(reflectedGridView, "SelectedGridEntry");
        }
        private void SetGridViewItems(GridItem[] newItems)
        {
            var items = allGridEntriesAccessor.Get();
            if (items == null)
                return;

            if (newItems == null) newItems = new GridItem[0];

            var wasFocused = searchBox.Focused;

            if (gridViewEntriesAccessor == null)
                gridViewEntriesAccessor = new FieldAccessor(items, "entries");

            setScrollOffsetAccessor.Invoke(reflectedGridView, 0);

            gridViewEntriesAccessor.Set(newItems, items);
            gridViewEntriesAccessor.Set(newItems, topLevelGridEntriesAccessor.Get());

            totalPropsAccessor.Set(newItems.Length);
            selectedRowAccessor.Set(0);

            if (newItems.Length > 0)
                selectedGridEntryAccessor.Set(newItems[0]);

            ((Control)reflectedGridView).Invalidate();

            if (wasFocused)
                searchBox.Focus();
        }
        private GridItem[] GetGridViewItems()
        {
            var items = allGridEntriesAccessor.Get();
            if (items == null)
                return null;

            if (gridViewEntriesAccessor == null)
                gridViewEntriesAccessor = new FieldAccessor(items, "entries");

            return gridViewEntriesAccessor.Get(items) as GridItem[];
        }
        //private FieldAccessor gridViewAccesor = null;
        //private FieldInfo gridViewField = null;
        private void InitializeSearchBox()
        {
            if (searchBox != null) return;

            //const BindingFlags bflags = BindingFlags.Instance | BindingFlags.NonPublic;

            searchBox = new TextBox();
            searchBox.Location = new Point(0, 0);
            searchBox.Size = new Size(70, searchBox.Height);
            searchBox.BorderStyle = BorderStyle.Fixed3D;
            searchBox.Font = new Font("Tahoma", 8.25f);

            searchBoxBackColor = searchBox.BackColor;

            searchBox.TextChanged += (s, _) => ApplyFilter();

            // Hack: let's remove the read-only flag on the toolstrip controls collection
            var rofield = new FieldAccessor(ToolStrip.Controls, "_isReadOnly");
            rofield.Set(false);
            ToolStrip.Controls.Add(searchBox);
            rofield.Set(true);

            ToolStrip.SizeChanged += (s, _) => FixSearchBoxLocation();

            FixSearchBoxLocation();

            // And now initialize accessors
            InitializeAccessors();

            PropertyTabChanged += (s, _) => searchBox.Text = string.Empty;
            PropertySortChanged += (s, _) => searchBox.Text = string.Empty;
            SelectedObjectsChanged += (s, _) => searchBox.Text = string.Empty;
        }