diff --git a/src/System.Design/src/System.Design.Forwards.cs b/src/System.Design/src/System.Design.Forwards.cs index ef75c715d94..eb516de8b05 100644 --- a/src/System.Design/src/System.Design.Forwards.cs +++ b/src/System.Design/src/System.Design.Forwards.cs @@ -10,6 +10,7 @@ [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageIndexEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListControlStringCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewGroupCollectionEditor))] +[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewItemCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewSubItemCollectionEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringArrayEditor))] [assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringCollectionEditor))] diff --git a/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewItemCollectionEditor.cs b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewItemCollectionEditor.cs new file mode 100644 index 00000000000..99ea4e0d8b9 --- /dev/null +++ b/src/System.Windows.Forms.Design.Editors/src/System/Windows/Forms/Design/ListViewItemCollectionEditor.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.ComponentModel; +using System.ComponentModel.Design; + +namespace System.Windows.Forms.Design +{ + /// + /// Provides an editor for a ListView items collection. + /// + internal class ListViewItemCollectionEditor : CollectionEditor + { + /// + /// Initializes a new instance of the class. + /// + public ListViewItemCollectionEditor(Type type) : base(type) + { } + + /// + /// Retrieves the display text for the given list item. + /// + protected override string GetDisplayText(object value) + { + if (value == null) + { + return string.Empty; + } + + string text; + + PropertyDescriptor prop = TypeDescriptor.GetDefaultProperty(CollectionType); + if (prop != null && prop.PropertyType == typeof(string)) + { + text = (string)prop.GetValue(value); + + if (text != null && text.Length > 0) + { + return text; + } + } + + text = TypeDescriptor.GetConverter(value).ConvertToString(value); + + if (text == null || text.Length == 0) + { + text = value.GetType().Name; + } + + return text; + } + } +} diff --git a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs index 9e8818827a1..b15054bcc71 100644 --- a/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs +++ b/src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -90,7 +90,7 @@ public void EnsureUITypeEditorForType(Type type, Type expectedEditorType) //[InlineData(typeof(ListControl), "ValueMember", typeof(DataMemberFieldEditor))] //[InlineData(typeof(ListView), "Columns", typeof(ColumnHeaderCollectionEditor))] [InlineData(typeof(ListView), "Groups", typeof(ListViewGroupCollectionEditor))] - //[InlineData(typeof(ListView), "Items", typeof(ListViewItemCollectionEditor))] + [InlineData(typeof(ListView), "Items", typeof(ListViewItemCollectionEditor))] [InlineData(typeof(ListViewItem), "ImageIndex", typeof(ImageIndexEditor))] [InlineData(typeof(ListViewItem), "ImageKey", typeof(ImageIndexEditor))] [InlineData(typeof(ListViewItem), "StateImageIndex", typeof(ImageIndexEditor))]