Skip to content

Porting System.Windows.Forms.Design.ListViewGroupCollectionEditor #2196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/System.Design/src/System.Design.Forwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ImageCollectionEditor))]
[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.ListViewSubItemCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringArrayEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.StringCollectionEditor))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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;
using System.ComponentModel.Design.Serialization;

namespace System.Windows.Forms.Design
{
/// <summary>
/// Provides an editor for a ListView groups collection.
/// </summary>
internal class ListViewGroupCollectionEditor : CollectionEditor
{
private object _editValue;

public ListViewGroupCollectionEditor(Type type) : base(type)
{ }

/// <summary>
/// Creates a ListViewGroup instance.
/// </summary>
protected override object CreateInstance(Type itemType)
{
ListViewGroup lvg = (ListViewGroup)base.CreateInstance(itemType);

// Create an unique name for the list view group.
lvg.Name = CreateListViewGroupName((ListViewGroupCollection)_editValue);

return lvg;
}

private string CreateListViewGroupName(ListViewGroupCollection lvgCollection)
{
string lvgName = "ListViewGroup";
string resultName;
INameCreationService ncs = GetService(typeof(INameCreationService)) as INameCreationService;
IContainer container = GetService(typeof(IContainer)) as IContainer;

if (ncs != null && container != null)
{
lvgName = ncs.CreateName(container, typeof(ListViewGroup));
}

// strip the digits from the end.
while (char.IsDigit(lvgName[lvgName.Length - 1]))
{
lvgName = lvgName.Substring(0, lvgName.Length - 1);
}

int i = 1;
resultName = lvgName + i.ToString(System.Globalization.CultureInfo.CurrentCulture);

while (lvgCollection[resultName] != null)
{
i++;
resultName = lvgName + i.ToString(System.Globalization.CultureInfo.CurrentCulture);
}

return resultName;
}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
_editValue = value;
object ret;

// This will block while the ListViewGroupCollectionDialog is running.
ret = base.EditValue(context, provider, value);

// The user is done w/ the ListViewGroupCollectionDialog.
// Don't need the edit value any longer
_editValue = null;

return ret;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void EnsureUITypeEditorForType(Type type, Type expectedEditorType)
//[InlineData(typeof(ListControl), "FormatString", typeof(FormatStringEditor))]
//[InlineData(typeof(ListControl), "ValueMember", typeof(DataMemberFieldEditor))]
//[InlineData(typeof(ListView), "Columns", typeof(ColumnHeaderCollectionEditor))]
//[InlineData(typeof(ListView), "Groups", typeof(ListViewGroupCollectionEditor))]
[InlineData(typeof(ListView), "Groups", typeof(ListViewGroupCollectionEditor))]
//[InlineData(typeof(ListView), "Items", typeof(ListViewItemCollectionEditor))]
[InlineData(typeof(ListViewItem), "ImageIndex", typeof(ImageIndexEditor))]
[InlineData(typeof(ListViewItem), "ImageKey", typeof(ImageIndexEditor))]
Expand Down