1.描述
介绍如何添加查询条件设置。
查看完整代码请参见:https://gitee.com/huozige-china/my-list-cell-type/blob/master/MyListCellType.cs。
2.添加查询条件设置
操作步骤
添加一个属性,类型为object。
添加一个命令来打开查询条件对话框。
为超链接属性指定编辑器,并执行在上一步中设置的命令。
[Designer("MyListCellType.MyListCellTypeDesigner,MyListCellType")]
public class MyListCellType: CellType
{
public string TableName
{
get; set;
}
public string TextColumn
{
get; set;
}
public object QueryCondition
{
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 == "QueryCondition")
{
return new HyperlinkEditorSetting(new ShowQueryConditionDialogCommand(builderContext, this.CellType.TableName));
}
return base.GetEditorSetting(property, builderContext);
}
}
internal class ShowQueryConditionDialogCommand : ICommand
{
private IBuilderContext builderContext;
private string tableName;
public ShowQueryConditionDialogCommand(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 queryCondition = (parameter as IEditorSettingsDataContext).Value;
var window = builderContext.GetQueryConditionWindow(queryCondition, this.tableName);
window.Closed += (object sender, EventArgs e) =>
{
if (window.DialogResult == true)
{
(parameter as IEditorSettingsDataContext).Value = window.QueryCondition;
}
};
window.ShowDialog();
}
}
重新构建工程并重启设计器,选择单元格并设置其类型为新创建的“MyListCellType”,单击单元格设置中的“QueryCondition”,则会弹出“查询条件设置”窗口,如下所示:
