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

news/2025/3/11 13:26:47/

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

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

获取DevExpress WPF v24.2正式版下载

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

DevExpress WPF中文教程图集

创建栏(Bands)

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

DevExpress WPF中文教程图集

在设计时

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

DevExpress WPF中文教程图集

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

DevExpress WPF中文教程图集

在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.ppmy.cn/news/1578354.html

相关文章

DINOv2:无监督学习强大的视觉特征

Paper Title: DINOv2: Learning Robust Visual Features without Supervision 论文发布于CVPR2023 DINOv2是一种无监督学习的计算机视觉模型,该模型在处理多种视觉任务时,不需要进行微调便能提供优异的性能。 上图展示了 PCA(主成分分析)方法在图像补丁上的应用。具体来说…

python中如何把dataframe转换为列表及其性能比较

在Python中&#xff0c;将DataFrame转换为列表常用的方法有以下几种&#xff1a; ### 1. 使用values属性 先通过values属性将DataFrame转换为NumPy数组&#xff0c;然后再调用tolist()方法将数组转换为列表。这是一种简单直接的方式&#xff0c;适用于快速将整个DataFrame转换…

三维仿射变换矩阵

三维仿射变换矩阵 平移变换缩放变换旋转变换绕x、y、z单个轴旋转的变换绕任意轴旋转 三维仿射变换矩阵有 3 4 、 4 4 3\times4、4\times4 34、44两种写法&#xff0c;都是施加到三维点的齐次式上&#xff0c; 4 4 4\times4 44的仿射变换矩阵是在 3 4 3\times4 34的矩阵后追…

Node.js和Vue CLI 安装指南(Windows 系统)

Node.js 与 Vue CLI 安装指南&#xff08;Windows 系统&#xff09; 一、Node.js 安装步骤 1. 安装包获取 官网下载&#xff1a;Node.js 官网推荐选择 LTS 版本&#xff08;长期支持版&#xff09;双击运行安装包&#xff1a; 2. 安装向导配置 点击 "Next" 进入…

本周行情——20250308

本周A股行情总结及主线阶段分析 &#xff08;2025年3月3日-3月7日&#xff09; 一、整体行情回顾 市场情绪&#xff1a; 前半周&#xff08;3月3日-5日&#xff09;&#xff1a;市场情绪持续回暖&#xff0c;涨停家数从66家增至115家&#xff0c;主线板块&#xff08;机器人、…

Docker入门篇1:搜索镜像、拉取镜像、查看本地镜像列表、删除本地镜像

大家好我是木木&#xff0c;在当今快速发展的云计算与云原生时代&#xff0c;容器化技术蓬勃兴起&#xff0c;Docker 作为实现容器化的主流工具之一&#xff0c;为开发者和运维人员带来了极大的便捷 。下面我们一起开始入门第一篇&#xff1a;搜索镜像、拉取镜像、查看本地镜像…

NO.29十六届蓝桥杯备战|string九道练习|reverse|翻转|回文(C++)

P5015 [NOIP 2018 普及组] 标题统计 - 洛谷 #include <bits/stdc.h> using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);string s;getline(cin, s);int sz s.size();int cnt 0;for (int i 0; i < sz; i){if (isspace(s[i]))continue…

【单片机】嵌入式系统的硬件与软件特性

嵌入式系统的软件结构 嵌入式系统的软件结构一般分为 不带操作系统&#xff08;Bare Metal&#xff09; 和 带操作系统&#xff08;RTOS / Linux&#xff09; 两种。不同的软件架构适用于不同的应用场景&#xff0c;如 简单控制系统、实时控制系统、物联网、工业自动化等。 嵌…