Page tree
Skip to end of metadata
Go to start of metadata

1.描述

介绍如何添加排序条件设置。

查看完整代码请参见:https://gitee.com/huozige-china/my-list

2.添加排序条件设置

操作步骤

  添加一个属性,类型为object。

  添加一个命令来打开排序条件对话框。

  为超链接属性指定编辑器,并执行在上一步中设置的命令。

[Designer("MyListCellType.MyListCellTypeDesigner,MyListCellType")]
public class MyListCellType: CellType
{
    public string TableName
    {
        get; set;
    }
    public string TextColumn
    {
        get; set;
    }
    public object SortCondition
    {
        get; set;
    }
}


public class MyListCellTypeDesigner : CellTypeDesigner<MyListCellType>
{
    public override EditorSetting GetEditorSetting(PropertyDescriptor property, IBuilderContext builderContext)
    {
        if (property.Name == "TableName")
        {
            return new TableComboTreeSelectorEditorSetting();
        }
        if (property.Name == "TextColumn")
        {
            var columns = builderContext.EnumAllTableInfos().FirstOrDefault(t => t.TableName == this.CellType.TableName)?.Columns?.Select(c => c.ColumnName);
            return new ComboEditorSetting(columns);
        }
        if (property.Name == "SortCondition")
        {
            return new HyperlinkEditorSetting(new ShowSortConditionDialogCommand(builderContext, this.CellType.TableName));
        }
        return base.GetEditorSetting(property, builderContext);
    }
}
internal class ShowSortConditionDialogCommand : ICommand
{
    private IBuilderContext builderContext;
    private string tableName;
    public ShowSortConditionDialogCommand(IBuilderContext builderContext, string tableName)
    {
        this.builderContext = builderContext;
        this.tableName = tableName;
    }
#pragma warning disable CS0067
        public event EventHandler CanExecuteChanged;
#pragma warning restore CS0067
    public bool CanExecute(object parameter)
    {
        return true;
    }
    public void Execute(object parameter)
    {
        var sortCondition = (parameter as IEditorSettingsDataContext).Value;
        var window = builderContext.GetSortConditionWindow(sortCondition, this.tableName);
        window.Closed += (object sender, EventArgs e) => 
        {
            if (window.DialogResult == true)
            {
                (parameter as IEditorSettingsDataContext).Value = window.SortCondition;
            }
        };
        window.ShowDialog();
    }
}

重新构建工程并重启设计器,选择单元格并设置其类型为新创建的“MyListCellType”,单击单元格设置中的“SortCondition”,则会弹出“排序条件设置”窗口,如下所示:


回到顶部

  • No labels