界面控件DevExpress WinForms中文教程:Banded Grid View - API

DevExpress WinForms擁有180+組件和UI庫,能為Windows Forms平臺創建具有影響力的業務解決方案。DevExpress WinForms能完美構建流暢、美觀且易于使用的應用程序,無論是Office風格的界面,還是分析處理大批量的業務數據,它都能輕松勝任!

DevExpress WinForms中文使用教程圖集

在本教程中,您將學習如何使用DevExpress WinForms在代碼中創建帶狀和高級帶狀布局。首先將主視圖切換到所需的類型,然后您將創建第一級帶狀和子帶狀來創建層次結構。初始化帶狀之后,將創建列并將它們鏈接到父帶狀,最后您將切換到高級帶狀網格視圖,把列移動到第二行,并讓列標題填充它們下面的空白空間。

獲取DevExpress WinForms 正式版下載

開始

從一個綁定到Car數據庫的Grid Control應用程序開始。

DevExpress WinForms中文使用教程圖集

切換到帶狀網格視圖

Ribbon控件中的Create Banded Layout按鈕將啟動把布局切換到帶狀視圖的代碼,在Click事件處理程序中,創建一個BandedGridView實例,禁用其ColumnViewOptionsBehavior.AutoPopulateColumns選項,并將結果對象分配給網格的GridControl.MainView?屬性。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// Switch to the Banded Grid View.
BandedGridView view = new BandedGridView();
view.OptionsBehavior.AutoPopulateColumns = false;
gridControl1.MainView = view;
}

運行應用程序并單擊Create Banded Layout按鈕,布局切換了,但是新創建的View是空的,因為禁用了自動列生成。

DevExpress WinForms中文使用教程圖集

創建頂級Bands

關閉應用程序并返回處理程序代碼,創建GridBand實例,在頂層分層級別添加Main、Performance Attributes和Notes band,將對象添加到視圖的BandedGridView.Bands集合中。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// ...
// Create top-level bands.
GridBand bandMain = new GridBand() { Name = "bandMain", Caption = "Main" };
GridBand bandPerformanceAttributes = new GridBand() { Name = "bandPerformance", Caption = "Performance Attributes" };
GridBand bandNotes = new GridBand() { Name = "bandNotes", Caption = "Notes" };
view.Bands.AddRange(new GridBand[] { bandMain, bandPerformanceAttributes, bandNotes });
}

運行應用程序,單擊按鈕,現在視圖將顯示bands。

DevExpress WinForms中文使用教程圖集

創建嵌套Bands

這一次,創建嵌套bands,為此創建新的band對象并將它們添加到主band的GridBand.Children集合中。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// ...
// Create nested bands.
GridBand bandModel = new GridBand { Name = "bandModel", Caption = "Model" };
GridBand bandPrice = new GridBand { Name = "bandPrice", Caption = "Price" };
bandMain.Children.AddRange(new GridBand[] { bandModel, bandPrice });
}

運行應用程序并單擊按鈕來查看新的分層band結構。

DevExpress WinForms中文使用教程圖集

創建帶狀列

返回到單擊處理程序代碼并創建由BandedGridColumn對象表示的列,初始化它們的GridColumn.FieldName屬性并使它們可見,將創建的列添加到視圖的BandedGridView.Columns集合中。

使用GridColumn.DisplayFormat屬性將Price列值格式化為貨幣。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// ...
// Create banded grid columns and make them visible.
BandedGridColumn colTrademark = new BandedGridColumn() { Name = "colTrademark", FieldName = "Trademark", Visible = true };
BandedGridColumn colModel = new BandedGridColumn() { Name = "colModel", FieldName = "Model", Visible = true };
BandedGridColumn colCategory = new BandedGridColumn() { Name = "colCategory", FieldName = "Category", Visible = true };
BandedGridColumn colPrice = new BandedGridColumn() { Name = "colPrice", FieldName = "Price", Visible = true };
BandedGridColumn colHP = new BandedGridColumn() { Name = "colHP", FieldName = "HP", Visible = true };
BandedGridColumn colLiter = new BandedGridColumn() { Name = "colLiter", FieldName = "Liter", Visible = true };
BandedGridColumn colCyl = new BandedGridColumn() { Name = "colCyl", FieldName = "Cyl", Visible = true };
BandedGridColumn colDescription = new BandedGridColumn() { Name = "colDescription", FieldName = "Description", Visible = true };
BandedGridColumn colPicture = new BandedGridColumn() { Name = "colPicture", FieldName = "Picture", Visible = true };
view.Columns.AddRange(new BandedGridColumn[] { colTrademark, colModel, colCategory, colPrice, colHP, colLiter, colCyl, colDescription, colPicture });// Format the Price column values as currency.
colPrice.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
colPrice.DisplayFormat.FormatString = "c2";
}

運行應用程序并再次點擊按鈕,列沒有顯示在視圖中,這是因為它們還沒有鏈接到bands 。

DevExpress WinForms中文使用教程圖集

為Bands分配列

要將列添加到Bands中,請設置列的BandedGridColumn.OwnerBand屬性。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// ...
// Assign columns to bands.
colTrademark.OwnerBand = bandModel;
colModel.OwnerBand = bandModel;
colCategory.OwnerBand = bandModel;
colPrice.OwnerBand = bandPrice;
colHP.OwnerBand = bandPerformanceAttributes;
colLiter.OwnerBand = bandPerformanceAttributes;
colCyl.OwnerBand = bandPerformanceAttributes;
colDescription.OwnerBand = bandNotes;
colPicture.OwnerBand = bandNotes;
}

運行應用程序,單擊按鈕,可以看到列現在在相應的bands下可見。

DevExpress WinForms中文使用教程圖集

切換到高級帶狀網格視圖

返回代碼并修改處理程序,使其創建高級帶狀網格視圖替代標準帶狀網格視圖,只需為視圖使用一個不同的類,其余的代碼將繼續工作。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// Switch to the Advanced Banded Grid View.
AdvBandedGridView view = new AdvBandedGridView();
view.OptionsBehavior.AutoPopulateColumns = false;
gridControl1.MainView = view;
// ...
}

運行應用程序,布局和以前一樣,只是列的自動寬度功能現在被禁用了。

將列排列成多行

關閉應用程序并將列標題排列到多行中,要在父bands內的其他列下顯示Category和Liter列,請將它們的?BandedGridColumn.RowIndex?屬性設置為1。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// ...
// Set the vertical position of column headers.
colCategory.RowIndex = 1;
colLiter.RowIndex = 1;
}

再次運行應用程序,可以看到更改,但是現在在某些列標題下出現了空格。

DevExpress WinForms中文使用教程圖集

自動拉伸列標題

要自動修改列標題的高度來填充空白空間,請啟用它們的BandedGridColumn.AutoFillDown選項。

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemCl
// ...
// Stretch columns to fit empty spaces below them.
colPrice.AutoFillDown = true;
colDescription.AutoFillDown = true;
colPicture.AutoFillDown = true;
}

運行應用程序并再次單擊Create Banded Layout按鈕來查看最終結果。

DevExpress WinForms中文使用教程圖集

完整代碼

C#

private void btnCreateBandedLayout_ItemClick(object sender, ItemClickEventArgs e) {
// Switch to the Advanced Banded Grid View.
AdvBandedGridView view = new AdvBandedGridView();
view.OptionsBehavior.AutoPopulateColumns = false;
gridControl1.MainView = view;// Create top-level bands.
GridBand bandMain = new GridBand() { Name = "bandMain", Caption = "Main" };
GridBand bandPerformanceAttributes = new GridBand() { Name = "bandPerformance", Caption = "Performance Attributes" };
GridBand bandNotes = new GridBand() { Name = "bandNotes", Caption = "Notes" };
view.Bands.AddRange(new GridBand[] { bandMain, bandPerformanceAttributes, bandNotes });// Create nested bands.
GridBand bandModel = new GridBand { Name = "bandModel", Caption = "Model" };
GridBand bandPrice = new GridBand { Name = "bandPrice", Caption = "Price" };
bandMain.Children.AddRange(new GridBand[] { bandModel, bandPrice });// Create banded grid columns and make them visible.
BandedGridColumn colTrademark = new BandedGridColumn() { Name = "colTrademark", FieldName = "Trademark", Visible = true };
BandedGridColumn colModel = new BandedGridColumn() { Name = "colModel", FieldName = "Model", Visible = true };
BandedGridColumn colCategory = new BandedGridColumn() { Name = "colCategory", FieldName = "Category", Visible = true };
BandedGridColumn colPrice = new BandedGridColumn() { Name = "colPrice", FieldName = "Price", Visible = true };
BandedGridColumn colHP = new BandedGridColumn() { Name = "colHP", FieldName = "HP", Visible = true };
BandedGridColumn colLiter = new BandedGridColumn() { Name = "colLiter", FieldName = "Liter", Visible = true };
BandedGridColumn colCyl = new BandedGridColumn() { Name = "colCyl", FieldName = "Cyl", Visible = true };
BandedGridColumn colDescription = new BandedGridColumn() { Name = "colDescription", FieldName = "Description", Visible = true };
BandedGridColumn colPicture = new BandedGridColumn() { Name = "colPicture", FieldName = "Picture", Visible = true };
view.Columns.AddRange(new BandedGridColumn[] { colTrademark, colModel, colCategory, colPrice, colHP, colLiter, colCyl, colDescription, colPicture });// Format the Price column values as currency.
colPrice.DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
colPrice.DisplayFormat.FormatString = "c2";// Assign columns to bands.
colTrademark.OwnerBand = bandModel;
colModel.OwnerBand = bandModel;
colCategory.OwnerBand = bandModel;
colPrice.OwnerBand = bandPrice;
colHP.OwnerBand = bandPerformanceAttributes;
colLiter.OwnerBand = bandPerformanceAttributes;
colCyl.OwnerBand = bandPerformanceAttributes;
colDescription.OwnerBand = bandNotes;
colPicture.OwnerBand = bandNotes;// Set the vertical position of column headers.
colCategory.RowIndex = 1;
colLiter.RowIndex = 1;// Stretch columns to fit empty spaces below them.
colPrice.AutoFillDown = true;
colDescription.AutoFillDown = true;
colPicture.AutoFillDown = true;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/81466.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/81466.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/81466.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

4G物聯網模塊實現廢氣處理全流程數據可視化監控配置

一、項目背景 隨著工業化進程的加速,工業廢氣的排放對環境造成了嚴重影響,廢氣處理廠應運而生。然而,廢氣處理廠中的設備眾多且分散,傳統的人工巡檢和數據記錄方式效率低下,難以及時發現問題。為了實現對廢氣處理設備…

Kubernetes控制平面組件:Kubelet詳解(四):gRPC 與 CRI gRPC實現

云原生學習路線導航頁(持續更新中) kubernetes學習系列快捷鏈接 Kubernetes架構原則和對象設計(一)Kubernetes架構原則和對象設計(二)Kubernetes架構原則和對象設計(三)Kubernetes控…

【數據結構】線性表--隊列

【數據結構】線性表--隊列 一.什么是隊列二.隊列的實現1.隊列結構定義:2.隊列初始化函數:3.隊列銷毀函數:4.入隊列函數(尾插):5.出隊列函數(頭刪):6.取隊頭元素&#xff…

C語言—再學習(結構體)

一、建立結構體 用戶自己建立由不同類型數據組成的組合型的數據結構,它稱為結構體。 struct Student { int num; //學號char name[20]; //名字為字符串char sex; //性別int age; //年紀float score; //分數char addr[30]; 地址為字符…

【前端基礎】10、CSS的偽元素(::first-line、::first-letter、::before、::after)【注:極簡描述】

一、偽元素的作用 選取某個特定的元素。 二、::first-line、::first-letter ::first-line:針對首行文本設置屬性 ::first-letter:針對首字母設置屬性 三、::before、::after 在一個元素之前(::before)或者之后(…

系統漏洞掃描服務:維護網絡安全的關鍵與服務原理?

系統漏洞掃描服務是維護網絡安全的關鍵措施,能夠迅速發現系統中的潛在風險,有效預防可能的風險和損失。面對網絡攻擊手段的日益復雜化,這一服務的重要性日益顯著。 服務原理 系統漏洞掃描服務猶如一名恪盡職守的安全守護者。它運用各類掃描…

從 Excel 到 Data.olllo:數據分析師的提效之路

背景:Excel 的能力邊界 對許多數據分析師而言,Excel 是入門數據處理的第一工具。然而,隨著業務數據量的增長,Excel 的一些固有限制逐漸顯現: 操作容易出錯,難以審計; 打開或操作百萬行數據時&…

框架的源碼理解——V3中的ref和reactive

最近在研究各個框架的源碼,從源碼角度去理解 vue3 的 reactive 和 ref API,記錄下研究的成果 reactive 首先,reactive() 的參數必須是一個對象,返回值是一個 Proxy 對象,具有響應性。如果參數不是對象類型&#xff0…

能源數字化轉型關鍵引擎:Profinet轉Modbus TCP網關驅動設備協同升級

在工業自動化的世界中,ModbusTCP和Profinet是兩個非常重要的通訊協議。ModbusTCP以其開放性和易用性,被廣泛應用于各種工業設備中;而Profinet則以其高效性和實時性,成為了眾多高端設備的首選。然而,由于這兩種協議的差…

【ant design】ant-design-vue 4.0實現主題色切換

官網&#xff1a;Ant Design Vue — An enterprise-class UI components based on Ant Design and Vue.js 我圖方便&#xff0c;直接在 app.vue 中加入的 <div class"app-content" v-bind:class"appOption.appContentClass"><a-config-provider…

一個指令,讓任意 AI 快速生成思維導圖

大家好&#xff0c;我是安仔&#xff0c;一個每天都在壓榨 AI 的躺平打工人。 今天分享一個 AI 辦公小技巧&#xff0c;讓你用一個指令讓 AI 生成思維導圖。 DeepSeek、Kimi、豆包都可以哈 &#xff5e; KimiXMind 安仔經常用 XMind 來繪制思維導圖&#xff0c;但是 AI 是沒…

便捷的批量打印工具推薦

軟件介紹 本文介紹的軟件是一款批量打印軟件&#xff0c;名為PrintConductor。 軟件功能強大 這款批量打印軟件功能極為強大&#xff0c;它不僅能夠批量打印各種不同格式的文件&#xff0c;還可以直接打印整個文件夾。 初次使用設置 第一次打開這款軟件時&#xff0c;要記…

USRP 射頻信號 采集 回放 系統

USRP 射頻信號采集回放系統 也可以叫做&#xff1a; 利用寬帶RF錄制和回放系統實現6G技術研究超寬帶射頻信號采集回放系統使用NI USRP平臺實現射頻信號錄制和回放操作演示USRP也能實現多通道寬帶信號流盤回放了&#xff01; 對于最簡單的實現方法就是使用LabVIEW進行實現 采…

MFC 調用海康相機進行軟觸發

初始化相機類文件 #pragma once #include "MvCameraControl.h" class CMvCamera { public:CMvCamera();~CMvCamera();//初始化相機int InitCamera();int SaveCurrentImage(CString filePath);//關閉相機void CloseCamera();//設置int SetEnumValue(IN const char* s…

虛擬主播肖像權保護,數字時代的法律博弈

首席數據官高鵬律師團隊 在虛擬主播行業蓬勃發展的表象之下&#xff0c;潛藏著一場關乎法律邊界的隱形戰爭。當一位虛擬偶像的3D模型被非法拆解、面部數據被批量復制&#xff0c;運營方驚訝地發現——傳統的肖像權保護體系&#xff0c;竟難以完全覆蓋這具由代碼與數據構成的“…

ArrayList-集合使用

自動擴容&#xff0c;集合的長度可以變化&#xff0c;而數組長度不變&#xff0c;集合更加靈活。 集合只能存引用數據類型&#xff0c;不能直接存基本數據類型&#xff0c;除非包裝 ArrayList會拿[]展示數據

鴻蒙ArkUI體驗:Hexo博客客戶端開發心得

最近部門也在跟進鴻蒙平臺的業務開發&#xff0c;自己主要是做 Android 開發&#xff0c;主要使用 Kotlin/Java 語言。&#xff0c;需要對新的開發平臺和開發模式進行學習&#xff0c;在業余時間開了個項目練手&#xff0c;做了個基于 Hexo 博客內容開發的App。鴻蒙主要使用Ark…

【和春筍一起學C++】(十四)指針與const

將const用于指針&#xff0c;有兩種情況&#xff1a; const int *pt; int * const pt; 目錄 1. const int *pt 2. int * const pt 3. 擴展 1. const int *pt 首先看第一種情況&#xff0c;const在int的前面&#xff0c;有如下語句&#xff1a; int peoples12&#xff1…

本地緩存更新方案探索

文章目錄 本地緩存更新方案探索1 背景2 方案探索2.1 初始化2.2 實時更新2.2.1 長輪詢2.2.1.1 client2.2.2.2 server 本地緩存更新方案探索 1 背景 大家在工作中是否遇到過某些業務數據需要頻繁使用&#xff0c;但是數據量不大的情況&#xff0c;一般就是幾十條甚至幾百條這種…

深入理解 requestIdleCallback:瀏覽器空閑時段的性能優化利器

requestIdleCallback 核心作用 requestIdleCallback 是瀏覽器提供的 API&#xff0c;用于將非關鍵任務延遲到瀏覽器空閑時段執行&#xff0c;避免阻塞用戶交互、動畫等關鍵任務&#xff0c;從而提升頁面性能體驗。 基本語法 const handle window.requestIdleCallback(callb…