没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:龚雪|2023-08-02 11:20:45.117|阅读 60 次
概述:本文主要介绍DevExpress WinForms的查找编辑器在v23.1中引入的多项选择功能,欢迎立即下载组件体验哦~
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
在最新发布的v23.1版本中,DevExpress WinForms Lookup Editor(查找编辑器)引入了一个非常受欢迎的功能——多项选择。在这种新的选择模式下,Lookup Editor显示一个带有复选框的列,用户可以使用鼠标或键盘选择查找项。
DevExpress WinForms 拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!
DevExpress技术交流群8:523159565 欢迎一起进群讨论
使用EditValueType属性来启用多项选择,此属性指定Lookup如何在其EditValue属性中存储所选值。可用的选项包括:
下面的示例演示如何激活多项选择,将查找的EditValue属性设置为一个带有id的列表,以便在应用程序启动时选择相应的产品。
using System.Windows.Forms; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Repository; public partial class Form1 : XtraForm { public Form1() { InitializeComponent(); lookUpEdit1.Properties.DataSource = ProductA.GetList(); lookUpEdit1.Properties.DisplayMember = "Name"; lookUpEdit1.Properties.ValueMember = "ID"; lookUpEdit1.Properties.EditValueType = LookUpEditValueType.ValueList; lookUpEdit1.EditValue = new List<object>() {0, 1, 4}; } } public class ProductA { int id; public ProductA(int id) { this.id = id; } [Display(Order = -1)] public int ID { get { return id; } } [Display(ShortName = "Bakery & Desserts")] public string Name { get; set; } [DisplayFormat(DataFormatString = "c2")] public double Price { get; set; } public static List<ProductA> GetList() { return new List<ProductA>() { new ProductA(0){ Name = "Butter Cake", Price = 56.99 }, new ProductA(1){ Name = "Chocolate Pie ", Price = 89.99 }, new ProductA(2){ Name = "Frozen Cookie Dough", Price = 54.99 }, new ProductA(3){ Name = "Truffie Cake", Price = 59.99 }, new ProductA(4){ Name = "Original Apple Pie", Price = 59.99 } }; } }
Lookup Editor(查找编辑器)可以保存有关数据源字段中所选项的信息,使用CheckBoxSelectorName属性指定包含所选项信息的字段名。如果此字段包含非布尔值类型,您还应该处理以下事件来根据需要 "convert" 字段值:
下面的示例演示了如何将选择绑定到“Selected”字段(带有布尔值):
public partial class Form1 : XtraForm { public Form1() { InitializeComponent(); lookUpEdit2.Properties.DataSource = ProductB.GetList(); lookUpEdit2.Properties.DisplayMember = "Name"; lookUpEdit2.Properties.ValueMember = "ID"; lookUpEdit2.Properties.CheckBoxSelectorMember = "Selected"; lookUpEdit2.Properties.EditValueType = LookUpEditValueType.ValueList; lookUpEdit2.EditValue = new List<object>() {0, 1}; } } public class ProductB { int id; public ProductB(int id) { this.id = id; } [Display(Order = -1)] public int ID { get { return id; } } [Display(ShortName = "Bakery & Desserts")] public string Name { get; set; } [DisplayFormat(DataFormatString = "c2")] public double Price { get; set; } public int InStock { get; set; } [Display(ShortName = "Add to Order")] public bool Selected { get; set; } public static List<ProductB> GetProductList() { return new List<ProductB>() { new ProductB(0){ Name = "Butter Cake", Price = 56.99, InStock = 50 }, new ProductB(1){ Name = "Chocolate Pie ", Price = 89.99, InStock = 32 }, new ProductB(2){ Name = "Frozen Cookie Dough", Price = 54.99, InStock = 0 }, new ProductB(3){ Name = "Truffie Cake", Price = 59.99, InStock = 42 }, new ProductB(4){ Name = "Original Apple Pie", Price = 59.99, InStock = 0} }; } }
从下面的截图中可以看到,lookup创建了一个选择器列(Add to Order),并将其绑定到“Selected”数据字段。
如果将EditValueType属性设置为LookUpEditValueType.ValueList,则可以将查找的EditValue属性绑定到只读集合类型属性,这个操作是由 设置控制的(默认情况下是启用的)。
using System.Windows.Forms; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Repository; public partial class Form1 : XtraForm { List<Item> orderItems; List<Order> orders; public Form1() { InitializeComponent(); orders = new List<Order>(){ new Order(10295), new Order(10296), new Order(10297) }; teOrder.DataBindings.Add(new Binding("EditValue", orders, "ID")); dataNavigator1.DataSource = orders; orderItems = new List<Item>() { new Item(){ ID = 0, ItemName = "Butter Cake", Price = 56.99 }, new Item(){ ID = 1, ItemName = "Chocolate Pie", Price = 89.99}, new Item(){ ID = 2, ItemName = "Frozen Cookie Dough", Price = 54.99}, new Item(){ ID = 3, ItemName = "Truffie Cake", Price = 59.99 }, new Item(){ ID = 4, ItemName = "Original Apple Pie", Price = 59.99 } }; lookupOrderItems.Properties.DataSource = orderItems; lookupOrderItems.Properties.DisplayMember = "ItemName"; lookupOrderItems.Properties.ValueMember = "ID"; lookupOrderItems.Properties.EditValueType = LookUpEditValueType.ValueList; lookupOrderItems.DataBindings.Add(new Binding("Editvalue", orders, "Items")); } } public class Order { int id; public Order(int id) { this.id = id; Items = new HashSet<int>(); } [Display(ShortName = "Order ID")] public int ID { get { return id; } } public HashSet<int> Items { get; private set; } } public class Item { public int ID { get; set; } public string ItemName { get; set; } public double Price { get; set; } }
使用此选项,您可以阻止用户根据特定条件选择项目,处理SelectionChanging事件并将e.Cancel参数设置为true来取消项目选择。
using DevExpress.XtraEditors.Controls; public partial class Form1 : XtraForm { List<ProductB> products; public Form1() { InitializeComponent(); //... lookUpEdit1.Properties.SelectionChanging += Properties_SelectionChanging; } private void Properties_SelectionChanging(object sender, PopupSelectionChangingEventArgs e) { e.Cancel = products[e.RecordIndex].InStock == 0; } }
重要提示:WinForms LookUpEdit控件可以选择多个项目,GridLookUpEdit、TreeListLookUpEdit和SearchLookUpEdit控件不支持此功能。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@dpuzeg.cn
文章转载自:慧都网本教程演示DevExpress WinForms的Banded Grid View 是如何进行用户自定义的,欢迎下载最新版组件体验!
可视化项目时间线对于有效规划和跟踪至关重要。在本篇教程中,您将学习如何使用 C# 在 Excel 中创建组合图,只需几行代码,即可自动生成动态、美观的组合图。
本文将为大家介绍DevExpress XAF将.NET Aspire集成到Blazor项目中后如何实现数据库依赖,欢迎下载最新版组件体验!
FP3 文件是使用流行的报表生成工具FastReport创建的报表。这种格式广泛用于存储可立即查看的报表数据,这些数据可以轻松共享或保存以供日后分析。但是,要打开和查看此类文件,需要一个特殊的程序——FastReport Viewer。
优秀的界面控件开发包,帮助企业构建卓越应用!
DevExpress DXperience Subscription高性价比的企业级.NET用户界面套包,助力企业创建卓越应用!
DevExpress WinForms Subscription为Windows Forms平台创建具有影响力的业务解决方案,高性价比WinForms界面控件套包。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@dpuzeg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢