Skip to content
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
2 changes: 1 addition & 1 deletion src/System.Design/src/System.Design.Forwards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;

[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.ColumnHeaderCollectionEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.DataMemberFieldConverter))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.FormatStringEditor))]
[assembly: TypeForwardedTo(typeof(System.Windows.Forms.Design.HelpNamespaceEditor))]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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
{
internal class ColumnHeaderCollectionEditor : CollectionEditor
{
/// <summary>
/// Initializes a new instance of the <see cref='System.Windows.Forms.Design.ImageCollectionEditor'/> class.
/// </summary>
public ColumnHeaderCollectionEditor(Type type) : base(type)
{
}

/// <summary>
/// Gets the help topic to display for the dialog help button or pressing F1. Override to display a different help topic.
/// </summary>
protected override string HelpTopic
{
get => "net.ComponentModel.ColumnHeaderCollectionEditor";
}

/// <summary>
/// Sets the specified collection to have the specified array of items.
/// </summary>
protected override object SetItems(object editValue, object[] value)
{
if (editValue is ListView.ColumnHeaderCollection list)
{
list.Clear();
ColumnHeader[] colHeaders = new ColumnHeader[value.Length];
Array.Copy(value, 0, colHeaders, 0, value.Length);
list.AddRange(colHeaders);
}
return editValue;
}

/// <summary>
/// Removes the item from listview column header collection
/// </summary>
internal override void OnItemRemoving(object item)
{
if (!(Context.Instance is ListView listview))
{
return;
}

if (item is ColumnHeader column)
{
IComponentChangeService cs = GetService(typeof(IComponentChangeService)) as IComponentChangeService;
PropertyDescriptor itemsProp = null;
if (cs != null)
{
itemsProp = TypeDescriptor.GetProperties(Context.Instance)["Columns"];
cs.OnComponentChanging(Context.Instance, itemsProp);
}
listview.Columns.Remove(column);

if (cs != null && itemsProp != null)
{
cs.OnComponentChanged(Context.Instance, itemsProp, null, null);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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 Xunit;

namespace System.Windows.Forms.Design.Tests
{
public class ColumnHeaderCollectionEditorTests
{
[Fact]
public void ColumnHeaderCollectionEditor_Ctor_Default()
{
var editor = new ColumnHeaderCollectionEditor(typeof(string));
Assert.False(editor.IsDropDownResizable);
}

[Fact]
public void ColumnHeaderCollectionEditor_EditValue_ReturnsValue()
{
var editor = new ColumnHeaderCollectionEditor(typeof(string));
string[] value = new string[] { "asdf", "qwer", "zxcv" };

Assert.Same(value, editor.EditValue(null, value));
}
}
}