From bc527a31afad49ff39b0d0bcfb6c71cfb3c8132e Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 15 Dec 2015 20:09:48 +0000 Subject: [PATCH] More intelligent content size checking on listview. --- DarkUI/Controls/DarkListView.cs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/DarkUI/Controls/DarkListView.cs b/DarkUI/Controls/DarkListView.cs index 47e9cde..35b71ce 100644 --- a/DarkUI/Controls/DarkListView.cs +++ b/DarkUI/Controls/DarkListView.cs @@ -148,7 +148,11 @@ namespace DarkUI.Controls private void Item_TextChanged(object sender, EventArgs e) { - UpdateContentSize(); + var item = (DarkListItem)sender; + + UpdateItemSize(item); + UpdateContentSize(item); + Invalidate(); } protected override void OnMouseDown(MouseEventArgs e) @@ -411,9 +415,31 @@ namespace DarkUI.Controls highestWidth = item.Area.Right + 1; } - ContentSize = new Size(highestWidth, Items.Count * ItemHeight); + var width = highestWidth; + var height = Items.Count * ItemHeight; - Invalidate(); + if (ContentSize.Width != width || ContentSize.Height != height) + { + ContentSize = new Size(width, height); + Invalidate(); + } + } + + private void UpdateContentSize(DarkListItem item) + { + var itemWidth = item.Area.Right + 1; + + if (itemWidth == ContentSize.Width) + { + UpdateContentSize(); + return; + } + + if (itemWidth > ContentSize.Width) + { + ContentSize = new Size(itemWidth, ContentSize.Height); + Invalidate(); + } } public void EnsureVisible()