AABBbaby

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

「应用界面美化」DevExpress Winform数据网格如何绑定数据

下载DevExpress v20.2完整版

上DevExpress中文网,获取第一手最新产品资讯!

DevExpress WinForms能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!

先决条件

平台:

  • Frameworks (XAF & XPO)
  • WinForms

产品:

这些新的只读服务器模式组件是XPServerCollectionSource/XPInstantFeedbackSourceXPView 的混合,可与DevExpress Grid控件一起使用。

它们提供以下内容:

  • 能以较低的内存使用量处理大型数据源(不会加载整个持久对象实例)。
  • 能自定义SELECT语句并排除未使用的数据列。
  • 能在根查询中包括引用属性数据,以避免1 + N问题。
  • 能包含使用ServerViewProperty在服务器端计算的自定义(虚拟)属性。

在将这些组件用作网格的数据源之前,请按以下方式配置它们:

1. 在代码或组件设计器中设置ObjectType和Properties,ServerViewProperty支持表达式中的持久性或别名属性。

C#

xpServerModeView1.ObjectType = typeof(Order);
xpInstantFeedbackView1.ObjectType = typeof(Order);

var viewProperties = new ServerViewProperty[] {
new ServerViewProperty("Oid", SortDirection.Ascending, "[Oid]"),
new ServerViewProperty("OrderDate", SortDirection.None, "[OrderDate]"),
new ServerViewProperty("Customer", SortDirection.None, "[Customer.ContactName]"),
new ServerViewProperty("ProductName", SortDirection.None, "[ProductName]"),
new ServerViewProperty("Price", SortDirection.None, "[Price]"),
new ServerViewProperty("Quantity", SortDirection.None, "[Quantity]"),
new ServerViewProperty("TotalPrice", SortDirection.None, "[Quantity] * [Price]"),
new ServerViewProperty("Tax", SortDirection.None, "[Quantity] * [Price] * 0.13")
};
xpServerModeView1.Properties.AddRange(viewProperties);
xpInstantFeedbackView1.Properties.AddRange(viewProperties);

2. 处理ResolveSession事件来提供一个Session,以从数据存储中检索对象。

C#

session = new Session(XpoDefault.DataLayer);

xpServerModeView1.ResolveSession += (s, e) => {
e.Session = session;
};

xpInstantFeedbackView1.ResolveSession += (s, e) => {
e.Session = session;
};

3. 对于XPInstantFeedbackView,可以选择处理DismissSession事件以手动处理在ResolveSession事件处理程序中创建的Session。

C#

 

xpInstantFeedbackView1.DismissSession += (s, e) => {
IDisposable session = e.Session as IDisposable;
if (session != null) {
session.Dispose();
}
};

 

DevExpress技术交流群2:775869749      欢迎一起进群讨论

posted on   AABBbaby  阅读(150)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2017-12-15 DevExpress WPF入门指南:如何自动或手动添加DXSplashScreen控件
点击右上角即可分享
微信分享提示