155 lines
4.0 KiB
C#
155 lines
4.0 KiB
C#
using System;
|
|
using System.Windows.Forms.Design;
|
|
using System.ComponentModel;
|
|
using System.Drawing.Design;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace WMS.Ctrl
|
|
{
|
|
public class ComplexItems : CollectionBase
|
|
{
|
|
public ComplexItems()
|
|
{
|
|
}
|
|
|
|
public ColumnsItem Add(ColumnsItem ci)
|
|
{
|
|
this.InnerList.Add(ci);
|
|
return ci;
|
|
}
|
|
|
|
public void AddRange(ColumnsItem[] ci)
|
|
{
|
|
InnerList.Clear();
|
|
this.InnerList.AddRange(ci);
|
|
}
|
|
|
|
public void Remove(ColumnsItem ci)
|
|
{
|
|
this.InnerList.Remove(ci);
|
|
}
|
|
|
|
public bool Contains(ColumnsItem ci)
|
|
{
|
|
return this.InnerList.Contains(ci);
|
|
}
|
|
|
|
public ColumnsItem this[int i]
|
|
{
|
|
get
|
|
{
|
|
return (ColumnsItem)this.InnerList[i];
|
|
}
|
|
set
|
|
{
|
|
this.InnerList[i] = value;
|
|
}
|
|
}
|
|
|
|
public ColumnsItem[] GetValues()
|
|
{
|
|
ColumnsItem[] ci = new ColumnsItem[this.InnerList.Count];
|
|
this.InnerList.CopyTo(0, ci, 0, this.InnerList.Count);
|
|
return ci;
|
|
}
|
|
}
|
|
|
|
public class ComplexItemCollectionEditor : System.ComponentModel.Design.CollectionEditor
|
|
{
|
|
|
|
private CollectionForm collectionForm;
|
|
|
|
public ComplexItemCollectionEditor(Type type)
|
|
: base(type)
|
|
{
|
|
}
|
|
|
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
|
{
|
|
|
|
if (this.collectionForm != null && this.collectionForm.Visible)
|
|
{
|
|
|
|
ComplexItemCollectionEditor editor = new ComplexItemCollectionEditor(this.CollectionType);
|
|
return editor.EditValue(context, provider, value);
|
|
}
|
|
|
|
else
|
|
{
|
|
return base.EditValue(context, provider, value);
|
|
}
|
|
}
|
|
|
|
|
|
protected override CollectionForm CreateCollectionForm()
|
|
{
|
|
this.collectionForm = base.CreateCollectionForm();
|
|
return this.collectionForm;
|
|
}
|
|
|
|
protected override object CreateInstance(Type ItemType)
|
|
{
|
|
|
|
ColumnsItem item = new ColumnsItem();
|
|
item.NameCmn = string.Empty;
|
|
item.NameCaption = string.Empty;
|
|
item.SelectCmn = false;
|
|
item.IndexVal = true;
|
|
|
|
return item;
|
|
}
|
|
}
|
|
|
|
public class CustomCollectionEditor : System.Drawing.Design.UITypeEditor
|
|
{
|
|
|
|
public delegate void CollectionChangedEventHandler(object sender, object instance, object value);
|
|
public event CollectionChangedEventHandler CollectionChanged;
|
|
|
|
private ITypeDescriptorContext _context;
|
|
|
|
private IWindowsFormsEditorService edSvc = null;
|
|
|
|
public CustomCollectionEditor()
|
|
{
|
|
}
|
|
|
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
|
|
{
|
|
if (context != null && context.Instance != null && provider != null)
|
|
{
|
|
object originalValue = value;
|
|
_context = context;
|
|
edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
|
|
|
|
if (edSvc != null)
|
|
{
|
|
FormColumn collEditorFrm = CreateForm(originalValue as List<ColumnsItem>);
|
|
collEditorFrm.ShowDialog();
|
|
}
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
|
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
|
{
|
|
if (context != null && context.Instance != null)
|
|
{
|
|
return UITypeEditorEditStyle.Modal;
|
|
}
|
|
return base.GetEditStyle(context);
|
|
}
|
|
|
|
|
|
protected virtual FormColumn CreateForm(List<ColumnsItem> s)
|
|
{
|
|
return new FormColumn(s);
|
|
}
|
|
|
|
|
|
}
|
|
}
|