Skip to content

Commit c7616c2

Browse files
vladimir-krestovRussKie
authored andcommitted
Ported ListViewGroupCollectionEditor
1 parent 7034876 commit c7616c2

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

src/System.Design/src/System.Design.Forwards.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageCollectionEditor))]
1010
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageIndexEditor))]
1111
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListControlStringCollectionEditor))]
12+
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewGroupCollectionEditor))]
1213
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ListViewSubItemCollectionEditor))]
1314
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringArrayEditor))]
1415
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringCollectionEditor))]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.ComponentModel;
6+
using System.ComponentModel.Design;
7+
using System.ComponentModel.Design.Serialization;
8+
9+
namespace System.Windows.Forms.Design
10+
{
11+
/// <summary>
12+
/// Provides an editor for a ListView groups collection.
13+
/// </summary>
14+
internal class ListViewGroupCollectionEditor : CollectionEditor
15+
{
16+
private object _editValue;
17+
18+
public ListViewGroupCollectionEditor(Type type) : base(type)
19+
{ }
20+
21+
/// <summary>
22+
/// Creates a ListViewGroup instance.
23+
/// </summary>
24+
protected override object CreateInstance(Type itemType)
25+
{
26+
ListViewGroup lvg = (ListViewGroup)base.CreateInstance(itemType);
27+
28+
// Create an unique name for the list view group.
29+
lvg.Name = CreateListViewGroupName((ListViewGroupCollection)_editValue);
30+
31+
return lvg;
32+
}
33+
34+
private string CreateListViewGroupName(ListViewGroupCollection lvgCollection)
35+
{
36+
string lvgName = "ListViewGroup";
37+
string resultName;
38+
INameCreationService ncs = GetService(typeof(INameCreationService)) as INameCreationService;
39+
IContainer container = GetService(typeof(IContainer)) as IContainer;
40+
41+
if (ncs != null && container != null)
42+
{
43+
lvgName = ncs.CreateName(container, typeof(ListViewGroup));
44+
}
45+
46+
// strip the digits from the end.
47+
while (char.IsDigit(lvgName[lvgName.Length - 1]))
48+
{
49+
lvgName = lvgName.Substring(0, lvgName.Length - 1);
50+
}
51+
52+
int i = 1;
53+
resultName = lvgName + i.ToString(System.Globalization.CultureInfo.CurrentCulture);
54+
55+
while (lvgCollection[resultName] != null)
56+
{
57+
i++;
58+
resultName = lvgName + i.ToString(System.Globalization.CultureInfo.CurrentCulture);
59+
}
60+
61+
return resultName;
62+
}
63+
64+
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
65+
{
66+
_editValue = value;
67+
object ret;
68+
69+
// This will block while the ListViewGroupCollectionDialog is running.
70+
ret = base.EditValue(context, provider, value);
71+
72+
// The user is done w/ the ListViewGroupCollectionDialog.
73+
// Don't need the edit value any longer
74+
_editValue = null;
75+
76+
return ret;
77+
}
78+
}
79+
}

src/System.Windows.Forms.Design.Editors/tests/UnitTests/EnsureEditorsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void EnsureUITypeEditorForType(Type type, Type expectedEditorType)
8989
//[InlineData(typeof(ListControl), "FormatString", typeof(FormatStringEditor))]
9090
//[InlineData(typeof(ListControl), "ValueMember", typeof(DataMemberFieldEditor))]
9191
//[InlineData(typeof(ListView), "Columns", typeof(ColumnHeaderCollectionEditor))]
92-
//[InlineData(typeof(ListView), "Groups", typeof(ListViewGroupCollectionEditor))]
92+
[InlineData(typeof(ListView), "Groups", typeof(ListViewGroupCollectionEditor))]
9393
//[InlineData(typeof(ListView), "Items", typeof(ListViewItemCollectionEditor))]
9494
[InlineData(typeof(ListViewItem), "ImageIndex", typeof(ImageIndexEditor))]
9595
[InlineData(typeof(ListViewItem), "ImageKey", typeof(ImageIndexEditor))]

0 commit comments

Comments
 (0)