当前位置: 首页 > news >正文

界面组件DevExpress WPF中文教程:Grid - 如何创建栏(Bands)?

DevExpress WPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序,这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 无论是Office办公软件的衍伸产品,还是以数据为中心的商业智能产品,都能通过DevExpress WPF控件来实现。

本文将为大家介绍如何使用DevExpress WPF GridControl创建栏(Bands)?欢迎下载最新版组件体验!

DevExpress新旧版本帮助文档获取可点击这篇文章查看——>《界面控件DevExpress v26.1帮助文档大全(CHM版本)》

DevExpress WPF GridControl的TableView和TreeListView允许你将列组织成逻辑组,这些组被称为栏(bands),每个栏(bands)由栏(bands)标题和子列组成,栏(bands)标题显示在栏(bands)子列上方的栏(bands)面板中。

创建栏(Bands)

栏(Bands)是GridControlBand对象,GridControl将其存储在GridControl.Bands集合中

在设计时

您可以使用GridControl的Quick Actions菜单来添加栏(Bands)。

DevExpress WPF GridControlBand的的Quick Actions菜单允许您添加子栏(Bands)和列,并指定栏(Bands)的Header属性:

在XAML中

1. 将GridControlBand对象添加到GridControl.Bands集合。

2. 使用栏(Bands)的Header属性指定栏(Bands)中显示的文本。

3. 用GridColumn对象填充栏(Bands)的Columns集合。

4. 指定列设置。

XAML

<dxg:GridControl ItemsSource="{Binding Source}"> <dxg:GridControl.Bands> <dxg:GridControlBand Header="Product"> <dxg:GridColumn FieldName="ProductName"/> </dxg:GridControlBand> <dxg:GridControlBand Header="Order Info"> <dxg:GridColumn FieldName="Country"/> <dxg:GridColumn FieldName="City"/> <dxg:GridColumn FieldName="OrderDate"/> </dxg:GridControlBand> <dxg:GridControlBand Header="Pricing"> <dxg:GridColumn FieldName="UnitPrice"/> <dxg:GridColumn FieldName="Quantity"/> </dxg:GridControlBand> </dxg:GridControl.Bands> </dxg:GridControl>
在代码中

C#

// Create band objects and specify their settings: var productBand = new GridControlBand(); productBand.Header = "Product"; productBand.Columns.Add(new GridColumn() { FieldName = nameof(Product.ProductName) }); var orderBand = new GridControlBand(); orderBand.Header = "Order Info"; orderBand.Columns.Add(new GridColumn() { FieldName = nameof(Product.Country) }); orderBand.Columns.Add(new GridColumn() { FieldName = nameof(Product.City) }); orderBand.Columns.Add(new GridColumn() { FieldName = nameof(Product.OrderDate) }); var pricingBand = new GridControlBand(); pricingBand.Header = "Pricing"; pricingBand.Columns.Add(new GridColumn() { FieldName = nameof(Product.UnitPrice) }); pricingBand.Columns.Add(new GridColumn() { FieldName = nameof(Product.Quantity) }); // Add bands to the GridControl: grid.Bands.Add(productBand); grid.Bands.Add(orderBand); grid.Bands.Add(pricingBand);

VB.NET

Dim productBand = New GridControlBand() productBand.Header = "Product" productBand.Columns.Add(New GridColumn() With { .FieldName = NameOf(Product.ProductName) }) Dim orderBand = New GridControlBand() orderBand.Header = "Order Info" orderBand.Columns.Add(New GridColumn() With { .FieldName = NameOf(Product.Country) }) orderBand.Columns.Add(New GridColumn() With { .FieldName = NameOf(Product.City) }) orderBand.Columns.Add(New GridColumn() With { .FieldName = NameOf(Product.OrderDate) }) Dim pricingBand = New GridControlBand() pricingBand.Header = "Pricing" pricingBand.Columns.Add(New GridColumn() With { .FieldName = NameOf(Product.UnitPrice) }) pricingBand.Columns.Add(New GridColumn() With { .FieldName = NameOf(Product.Quantity) }) grid.Bands.Add(productBand) grid.Bands.Add(orderBand) grid.Bands.Add(pricingBand)
使用数据注释属性

您可以使用数据注释属性将网格列分组为栏(Bands):

1. 将DisplayAttribute应用于数据源中的所有字段。

2. 使用DisplayAttribute.GroupName属性来指定栏(Bands)的标题。

3. 将DataControlBase.EnableSmartColumnsGeneration属性设置为true,来根据数据注释属性生成列。

XAML

<dxg:GridControl ItemsSource="{Binding Source}" AutoGenerateColumns="AddNew" EnableSmartColumnsGeneration="True"> <!-- ... --> </dxg:GridControl>

C#

using System.ComponentModel.DataAnnotations; // ... public class Product { [Display(GroupName = "Product")] public string ProductName { get; set; } [Display(GroupName = "Order Info")] public string Country { get; set; } [Display(GroupName = "Order Info")] public string City { get; set; } [Display(GroupName = "Pricing")] public double UnitPrice { get; set; } [Display(GroupName = "Pricing")] public int Quantity { get; set; } [Display(GroupName = "Order Info")] public DateTime OrderDate { get; set; } }

VB.NET

Imports System.ComponentModel.DataAnnotations ' ... Public Class Product <Display(GroupName:="Product")> Public Property ProductName As String <Display(GroupName:="Order Info")> Public Property Country As String <Display(GroupName:="Order Info")> Public Property City As String <Display(GroupName:="Pricing")> Public Property UnitPrice As Double <Display(GroupName:="Pricing")> Public Property Quantity As Integer <Display(GroupName:="Order Info")> Public Property OrderDate As DateTime End Class

绑定到没有GroupName属性的字段的列显示在第一个栏(Bands)中。

http://www.gsyq.cn/news/1636291.html

相关文章:

  • Spectre与Alphalens、Pyfolio无缝集成:完整的量化分析工作流
  • 2026,证件照换背景手机软件整理,免费换底色操作指南
  • 一站式图标解决方案:Monicon如何在5分钟内提升你的前端开发效率
  • 2026源码交付低代码平台价格实测:从5万到几十万,价差到底差在哪?
  • OWASP Top 10实战指南:从靶场搭建到漏洞攻防与防御体系构建
  • 炉石传说自动化技术挑战与Java/Kotlin解决方案深度实践
  • 【什么是非晶合金?非晶电机有什么优点?】
  • 5分钟快速上手:小米手表表盘设计终极指南
  • 未来医疗AI:QiZhenGPT医学知识库与大模型融合技术路线图
  • CANN/GE数据流构图API接口
  • Jina Reader API内容抓取稳定性深度解析:从原理剖析到实战优化指南
  • 深入掌控AMD Ryzen性能:SMU Debug Tool完全使用指南
  • Vault-Operator安全配置指南:TLS设置、RBAC和网络策略最佳实践
  • CANN/ge DataFlow MetaRunContext类
  • AMD Ryzen深度调试:解锁处理器性能潜力的终极指南
  • Sublime Text Orgmode插件常见问题解决方案:从安装到高级使用
  • MMKV如何解决移动端跨平台数据同步的三大核心挑战:实战指南
  • 从推箱子到世界模型:用PyTorch实现AI规划能力与JEPA架构解析
  • SVD++ 算法 Python 实现:利用隐式反馈将推荐准确率提升 3%
  • 一文读懂GhostDB的持久化机制:AOF日志与快照技术全解析
  • 终极macOS窗口管理神器:AutoRaise让鼠标悬停自动聚焦,工作效率提升300%
  • GoExec任务计划模块实战:demand与create命令实现无文件落地攻击
  • 如何快速上手YiShaAdmin:权限管理系统实战指南
  • 深度解析ValveResourceFormat:从VPK文件到3D模型的完整实战指南
  • 警惕AI模型标题党:解析Claude真实版本演进与评测逻辑
  • 基于深度学习的多模态音乐推荐系统实战
  • Kronos:用AI读懂金融市场的语言,开启股票预测新时代
  • CANN/cannbot-skills:验证报告输出模式定义
  • 大三嵌入式系统课程设计:打造nwpu-cram智能家居控制系统的完整指南
  • 2026年实测AI写作辅助软件合集(实测甄选版)