翻譯|使用教程|編輯:龔雪|2025-03-06 09:55:51.267|閱讀 87 次
概述:本文主要介紹如何使用DevExpress WPF Grid控件的創建欄(Bands),歡迎下載最新版組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業需求的高性能業務應用程序。通過DevExpress WPF能創建有著強大互動功能的XAML基礎應用程序,這些應用程序專注于當代客戶的需求和構建未來新一代支持觸摸的解決方案。 無論是Office辦公軟件的衍伸產品,還是以數據為中心的商業智能產品,都能通過DevExpress WPF控件來實現。
本文將為大家介紹如何使用DevExpress WPF GridControl創建欄(Bands)?歡迎下載最新版組件體驗!
DevExpress技術交流群11:749942875 歡迎一起進群討論
DevExpress WPF GridControl的TableView和TreeListView允許你將列組織成邏輯組,這些組被稱為欄(bands),每個欄(bands)由欄(bands)標題和子列組成,欄(bands)標題顯示在欄(bands)子列上方的欄(bands)面板中。
欄(Bands)是對象,GridControl將其存儲在集合中。
您可以使用GridControl的Quick Actions菜單來添加欄(Bands)。
DevExpress WPF GridControlBand的的Quick Actions菜單允許您添加子欄(Bands)和列,并指定欄(Bands)的Header屬性:
1. 將對象添加到集合。
2. 使用欄(Bands)的屬性指定欄(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. 使用屬性來指定欄(Bands)的標題。
3. 將屬性設置為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)中。
更多產品資訊及授權,歡迎來電咨詢:023-68661681
慧都科技是專注軟件工程、智能制造、石油工程三大行業的數字化解決方案服務商。在軟件工程領域,我們提供開發控件、研發管理、代碼開發、部署運維等軟件開發全鏈路所需的產品,提供正版授權采購、技術選型、個性化維保等服務,幫助客戶實現技術合規、降本增效與風險可控。
慧都科技是DevExpress的中國區的合作伙伴,DevExpress作為用戶界面領域的優秀產品,幫助企業高效構建權限管理、數據可視化(如網格/圖表/儀表盤)、跨平臺系統(WinForms/ASP.NET/.NET MAUI)及行業定制解決方案,加速開發并強化交互體驗。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網