// Performance bottleneck internal protected virtual void UpdateStyle() { // styles shouldn't be modified when we are not sited. if (this.IsSited == false) { return; } int level = this.Level; Padding p = this._previousPadding; Size preferredSize; // This line consumes lot of memory Graphics g = this.OwningNode._grid.GetGraphics(); preferredSize = this.GetPreferredSize(g, this.InheritedStyle, this.RowIndex, new Size(0, 0)); //preferredSize = new Size(20, 21); Image image = this.OwningNode.Image; if (image != null) { // calculate image size _imageWidth = image.Width + 2; _imageHeight = image.Height + 2; } else { _imageWidth = glyphWidth; _imageHeight = 0; } // TODO: Make this cleaner if (preferredSize.Height < _imageHeight) { int leftpad = p.Left + (level * INDENT_WIDTH) + _imageWidth + INDENT_MARGIN; // Performance bottleneck changing padding takes lot of time TreeGridView _grid = (TreeGridView)this.DataGridView; if (_grid.paddings_list.IndexOfKey(leftpad) >= 0) { this.Style = _grid.paddings_list.Values[leftpad]; } else { Padding npad = new Padding(leftpad, p.Top + (_imageHeight / 2), p.Right, p.Bottom + (_imageHeight / 2)); this.Style.Padding = npad; _grid.paddings_list.Add(leftpad, this.Style); } _imageHeightOffset = 2;// (_imageHeight - preferredSize.Height) / 2; } else { int leftpad = p.Left + (level * INDENT_WIDTH) + _imageWidth + INDENT_MARGIN; Padding oldpad = this.Style.Padding; // if ((oldpad.Left != npad.Left) || (oldpad.Top != npad.Top) || (oldpad.Right != npad.Right) || (oldpad.Bottom != npad.Bottom)) if (oldpad.Left != leftpad) { // Performance bottleneck changing padding takes lot of time TreeGridView _grid = (TreeGridView)this.DataGridView; if (_grid.paddings_list.IndexOfKey(leftpad) >= 0) { this.Style = _grid.paddings_list[leftpad]; } else { Padding npad = new Padding(leftpad, p.Top, p.Right, p.Bottom); this.Style.Padding = npad; _grid.paddings_list.Add(leftpad, this.Style); } } } calculatedLeftPadding = ((level - 1) * glyphWidth) + _imageWidth + INDENT_MARGIN; }