当前位置: 首页 > 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.jsqmd.com/news/1124308/

相关文章:

  • 一站式图标解决方案:Monicon如何在5分钟内提升你的前端开发效率
  • 2026,证件照换背景手机软件整理,免费换底色操作指南
  • CircularProgressView与MVVM架构集成:ViewModel中的进度管理
  • 大模型LangChain面试题及参考答案(上)
  • SENet-Tensorflow源码架构解析:理解项目文件结构与设计模式
  • 2026源码交付低代码平台价格实测:从5万到几十万,价差到底差在哪?
  • AI工程化实战:从工具使用到工作流设计的四大场景应用
  • OWASP Top 10实战指南:从靶场搭建到漏洞攻防与防御体系构建
  • Ryujinx Switch模拟器终极指南:免费畅玩4000+Switch游戏
  • Obsidian-skills:为AI代理注入Obsidian超能力,开启智能知识管理新纪元
  • 如何快速自定义Spotify字体:打造个性化音乐界面的完整指南
  • yuzu模拟器性能优化终极指南:从60fps到120fps的实战技巧
  • FlipperZeroHondaFirmware在教育与研究中的5大创新应用场景
  • Windows 11本地部署GLM-5.2大模型:11999元成本实现11t/s推理与Agent集成
  • 炉石传说自动化技术挑战与Java/Kotlin解决方案深度实践
  • Boss Show Time:基于时间维度的智能招聘信息筛选方案
  • TinyTorch教学框架:深度学习系统思维培养实践
  • 【什么是非晶合金?非晶电机有什么优点?】
  • WVP-GB28181-Pro项目中海康摄像头语音广播架构优化与故障排除指南
  • 如何快速掌握FFBox:面向开发者的终极FFmpeg转码工具箱完全指南
  • Ovine:革命性JSON驱动的管理系统构建框架,让UI开发效率提升10倍
  • 5分钟快速上手:小米手表表盘设计终极指南
  • 未来医疗AI:QiZhenGPT医学知识库与大模型融合技术路线图
  • React Three Fiber架构深度剖析:声明式3D渲染的工程化实践
  • MC74HC165A与TM4C1294NCPDT的GPIO扩展方案解析
  • CANN/GE数据流构图API接口
  • axi3 和 axi4 总线的区别
  • Vault-Operator安全配置指南:TLS设置、RBAC和网络策略最佳实践
  • 基于CNN的墙体污渍识别系统设计与优化
  • YOLO与DETR目标检测技术对比与RT-DETR实战指南