界面控件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.mzph.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…