翻譯|使用教程|編輯:龔雪|2025-03-06 09:55:51.267|閱讀 87 次
概述:本文主要介紹如何使用DevExpress WPF Grid控件的創(chuàng)建欄(Bands),歡迎下載最新版組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業(yè)需求的高性能業(yè)務(wù)應(yīng)用程序。通過DevExpress WPF能創(chuàng)建有著強大互動功能的XAML基礎(chǔ)應(yīng)用程序,這些應(yīng)用程序?qū)W⒂诋敶?戶的需求和構(gòu)建未來新一代支持觸摸的解決方案。 無論是Office辦公軟件的衍伸產(chǎn)品,還是以數(shù)據(jù)為中心的商業(yè)智能產(chǎn)品,都能通過DevExpress WPF控件來實現(xiàn)。
本文將為大家介紹如何使用DevExpress WPF GridControl創(chuàng)建欄(Bands)?歡迎下載最新版組件體驗!
DevExpress技術(shù)交流群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. 指定列設(shè)置。
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)
您可以使用數(shù)據(jù)注釋屬性將網(wǎng)格列分組為欄(Bands):
1. 將DisplayAttribute應(yīng)用于數(shù)據(jù)源中的所有字段。
2. 使用屬性來指定欄(Bands)的標題。
3. 將屬性設(shè)置為true,來根據(jù)數(shù)據(jù)注釋屬性生成列。
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
綁定到?jīng)]有GroupName屬性的字段的列顯示在第一個欄(Bands)中。
更多產(chǎn)品資訊及授權(quán),歡迎來電咨詢:023-68661681
慧都科技是專注軟件工程、智能制造、石油工程三大行業(yè)的數(shù)字化解決方案服務(wù)商。在軟件工程領(lǐng)域,我們提供開發(fā)控件、研發(fā)管理、代碼開發(fā)、部署運維等軟件開發(fā)全鏈路所需的產(chǎn)品,提供正版授權(quán)采購、技術(shù)選型、個性化維保等服務(wù),幫助客戶實現(xiàn)技術(shù)合規(guī)、降本增效與風險可控。
慧都科技是DevExpress的中國區(qū)的合作伙伴,DevExpress作為用戶界面領(lǐng)域的優(yōu)秀產(chǎn)品,幫助企業(yè)高效構(gòu)建權(quán)限管理、數(shù)據(jù)可視化(如網(wǎng)格/圖表/儀表盤)、跨平臺系統(tǒng)(WinForms/ASP.NET/.NET MAUI)及行業(yè)定制解決方案,加速開發(fā)并強化交互體驗。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)