简介:

XtraEditors   Library是专门为可视化的Studio.NET设计的最优化的一套100%的C#控件

XtraEdiotors Library是一款具有革命性的超过20种数据编辑控制的控件

它是国内第一款适合于.NET框架类型的控件。


准备工作

1. DevExpress控件的安装
2. Demo查看
3. 帮助文档使用


与.net基本的控件比较

1. 命名空间(NameSpace)
.net基本控件的类都在System.Windows.Forms的命名空间下
DevExpress的控件类在DevExpress命名空间


2. 可以代替.net的控件
DevExpress的大部分控件都已可以代替.net的基本控件。


如:

按钮:
System.Windows.Forms.Button -> DevExpress.XtraEditors.SimpleButton


文本框:
System.Windows.Forms.TextBox -> DevExpress.XtraEditors.TextEdit

复选框
System.Windows.Forms.CheckBox -> DevExpress.XtraEditors.CheckEdit

下拉框:
System.Windows.Forms.ComboBox -> DevExpress.XtraEditors.ComboBoxEdit


日 期:
System.Windows.Forms.DateTimePicker -> DevExpress.XtraEditors.DateEdit   /   DevExpress.XtraEditors.TimeEdit

这里就不一一列举了,认真看看,相信一定找出很多可以替代的控件


二. 几个比较重要、常用的属性

1:EditValue

DevExpress.XtraEditors.*Edit 的控件都不可少的一个EditValue属性。

如:DevExpress.XtraEditors.*Edit

通常,EditValue会跟Text的值是一样的。


只是EditValue的类型为Object,

Text的属性为String,

也就是EditValue通常可以代替Text属性。


2. Enable 和 Visable

是否禁用和是否可见


3. Properties

设置控件一些特征
DevExpress.XtraEditors.TextEdit   textEdit  =  …;

例如 是否只读:
textEdit.Properties.ReadOnly = true;


不允许获得焦点
textEdit.Properties.AllowFocused = false;


禁止空值输入
textEdit.Properties.AllowNullInput = false;

// 当这个属性应用在TimeEdit中,它的清除按钮,将会禁用(灰掉)喵喵喵???


禁止编辑器输入

ComboBoxEdit   comboBoxEdit  =  …;
comboBoxEdit.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;

// 只选模式,不能输入文本


4. Appearance 设置风格。

Dexpress把所有设置控件风格的特性都放到Appearance属性下。
例:
DevExpress.XtraEditors.SimpleButton  simpleButton = …;

//前景色
simpleButton.Appearance.ForeColor = Color.Red;

//背景色
simpleButton.Appearance.BackColor = Color.Red;


Appearance.TextOptions
文本对齐操作

// 居中对齐
simpleButton.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

// 自动换行。

// 当控件的宽度容不下文本的长度,会自动换行。
simpleButton.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWrap.Wrap;


注意:

在某些控件中, Properties属性下才有Apperarance
DevExpress.XtraEditors.TextEdit  textEdit =  …;
textEdit.Properties.Appearance.ForeColor = Color.Red;


三. 几个常用的控件

1:用强大的LookUpEdit代替ComboBox

1.1 ComboBox不支持数据绑定
2.1 由于DevExpress的ComboBox天生存在数据绑定缺陷,

所以有时我们要做数据绑定这种杀鸡小事时,不得不使用牛刀LooUpEdit


如下代码,可用实现一个ComboBox:

// 未闻花名vwhm.net
// 禁止文本输入
this.lookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
// 默认为null的显示
this.lookUpEdit1.Properties.NullText = "[请选择类别]";
// 加入一个显示列
this.lookUpEdit1.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Name"));
// 不显示页眉(包括列头)
this.lookUpEdit1.Properties.ShowHeader = false;
// 不显示页脚(包括关闭按钮)
this.lookUpEdit1.Properties.ShowFooter = false;
// 要显示的字段,Text获得
this.lookUpEdit1.Properties.DisplayMember = "Name";
// 实际值的字段,EditValue获得
this.lookUpEdit1.Properties.ValueMember = "Value";
// 数据绑定
ICollection list = Global.ClassCategoryList;
// 绑定数据
this.lookUpEdit1.Properties.DataSource = list;
// 设置行数(根据这个自动设置高度)
this.lookUpEdit1.Properties.DropDownRows = list.Count;


2. GridControl

GridControl可以代替.net的System.Windows.Forms.DataGrid控件。
GirdControl只是一个容器控件,必须要求GridView视图作为它的子控件。
GridControl可以包含多个视图,可以实现视图的切换


每个GridView视图必须包含列(Column)
GridControl支持层级视图


GridControl 经常设置的属性
使用导航器
this.gridControl1.UseEmbeddedNavigator = true;


this.gridControl1.EmbeddedNavigator.Buttons.Append.Visible = false;
this.gridControl1.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
this.gridControl1.EmbeddedNavigator.Buttons.Edit.Visible = false;
this.gridControl1.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
this.gridControl1.EmbeddedNavigator.Buttons.Remove.Visible = false;this.gridControl1.EmbeddedNavigator.Buttons.First.Visible = true;
this.gridControl1.EmbeddedNavigator.Buttons.Last.Visible = true;
this.gridControl1.EmbeddedNavigator.Buttons.Next.Visible = true;
this.gridControl1.EmbeddedNavigator.Buttons.NextPage.Visible = true;
this.gridControl1.EmbeddedNavigator.Buttons.Prev.Visible = true;
this.gridControl1.EmbeddedNavigator.Buttons.PrevPage.Visible = true;

GridView 经常设置的属性

// 禁止编辑
this.gridView1.OptionsBehavior.Editable = false;// 不允许使用过滤
this.gridView1.OptionsCustomization.AllowFilter = false;// 不允许使用排序
this.gridView1.OptionsCustomization.AllowSort = false;// 不显示组面板
this.gridView1.OptionsView.ShowGroupPanel = false;// 如果宽度溢出,自动出现滚动条this.gridView1.OptionsView.ColumnAutoWidth =true;// 禁止单元格获得焦点
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;// 选择的行背景透明
this.gridView1.Appearance.SelectedRow.BackColor = Color.Transparent;

事件

// 未闻花名vwhm.net
//订阅行焦点改变事件
this.gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(this.gridView1_FocusedRowChanged);//验证编辑器(单元格)值输入
this.gridView1.ValidatingEditor += new DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventHandler(this.gridView1_ValidatingEditor);private void gridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{if (gridView1.FocusedColumn == col产品名称){if (string.IsNullOrEmpty(e.Value as string)) {e.ErrorText = "产品名称不能为空";e.Valid = false;}}
}


// 未闻花名vwhm.net
//订阅设置行风格事件
this.gridView1.RowStyle += new DevExpress.XtraGrid.Views.Grid.RowStyleEventHandler(this.gridView1_RowStyle);private void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{object value = gridView1.GetRowCellValue(e.RowHandle, "中止");if (value!=null&&(bool)value) {e.Appearance.ForeColor = Color.Red;}
}this.gridView1.CustomColumnDisplayText += new DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventHandler(this.gridView1_CustomColumnDisplayText);private DataTable _CategoryList;public DataTable CategoryList {get {if (_CategoryList == null) {_CategoryList=GetData("select * from 产品类别");DataColumn pk = _CategoryList.Columns["类别ID"];_CategoryList.PrimaryKey = new DataColumn[] {pk};}return _CategoryList;}
}private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{if (e.Column.Name == "col类别ID") {e.DisplayText = CategoryList.Rows.Find(e.Value)["类别名称"] as string;}
}

// 行单元格对齐
this.gridView1.RowCellDefaultAlignment += new DevExpress.XtraGrid.Views.Base.RowCellAlignmentEventHandler(this.gridView1_RowCellDefaultAlignment);private void gridView1_RowCellDefaultAlignment(object sender, DevExpress.XtraGrid.Views.Base.RowCellAlignmentEventArgs e)
{e.HorzAlignment = DevExpress.Utils.HorzAlignment.Near;
}

3. 界面操作

3.1 根据条件操作行或列风格

3.2 添加RepositoryItem(内嵌元素In-place EditorRepository)

3.3 列汇总

首先,设置this.gridView1.OptionsView.ShowFooter = true;

this.col库存量.SummaryItem.DisplayFormat = “总量:{0}”;

// 六种:Sum,Average,Count,Max,Min,Custom
col单位数量.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;


四. 数据检查、验证

1. 演示Mask
2. DXValidationProvider的组件使用

DevExpress_常用控件入门相关推荐

  1. 鸡啄米之VS2010/MFC编程入门之二十四(常用控件:列表框控件ListBox)

    目录 一.目的: 1.点击列表框某个变量后,编辑框就显示出来这个变量名字 一.参考: 1.VS2010/MFC编程入门之二十四(常用控件:列表框控件ListBox) ①总结:good:亲测有效,适合多 ...

  2. VS2010/MFC编程入门之二十(常用控件:静态文本框)

    上一节鸡啄米讲了颜色对话框之后,关于对话框的使用和各种通用对话框的介绍就到此为止了.从本节开始鸡啄米将讲解各种常用控件的用法.常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组 ...

  3. MFC编程入门之二十(常用控件:静态文本框)

    上一节讲了颜色对话框之后,关于对话框的使用和各种通用对话框的介绍就到此为止了.从本节开始将讲解各种常用控件的用法.常用控件主要包括:静态文本框.编辑框.单选按钮.复选框.分组框.列表框.组合框.图片控 ...

  4. Android入门到精通|安卓/Android开发零基础系列Ⅱ【职坐标】-学习笔记(1)-- 常用控件及资源介绍

    前言 为了巩固Android基础知识,回顾一下学习内容,才有此学习笔记. IDE Androdi Studio 4 + Genymotion 创建项目 修改项目的 build.gradle,添加国内镜 ...

  5. C++/MFC-几种常用控件

    VS2010/MFC编程入门之二十(常用控件:静态文本框) VS2010/MFC编程入门之二十一(常用控件:编辑框Edit Control) VS2010/MFC编程入门之二十二(常用控件:按钮控件B ...

  6. 记录学习Android基础的心得05:常用控件(基础篇)

    文章目录 前言 一.复合按钮CompoundButton的常见子类 1.单选按钮RadioButton 2.复选框CheckBox 3.开关Switch 二.进度展示控件 1.进度条ProgressB ...

  7. VS2010-MFC(常用控件:静态文本框)

    转自:http://www.jizhuomi.com/software/179.html 关于对话框的使用和各种通用对话框的介绍就到此为止,从本节开始将讲解各种常用控件的用法.常用控件主要包括:静态文 ...

  8. 设计器的使用及常用控件

    设计器的使用及常用控件 文章目录 设计器的使用及常用控件 一.设计器 二.设计器中的常用控件 一.设计器 1.设计器的使用 2.通过代码操作ui文件 #include "mainwindow ...

  9. 零基础学Android之常用控件

    常用控件 上次我们讲了布局:线性布局.表格布局.帧布局和相对布局,这个布局,它是在整个移动端设计内容的一个框架的方式,以什么方式来设计界面.最终在界面里面,放置的是控件,所谓控件,就是程序员可以控制的 ...

最新文章

  1. 07JavaScript中的数组
  2. 摊牌了!国内首个基于结构光投影三维重建系列视频课程
  3. 把 Bug 晾几天就能解决了!!! | 每日趣闻
  4. RSA非对称加密算法Java实现之输出key文件
  5. php header
  6. 使用Spring Boot Actuator监视Java应用程序
  7. c# opencv 轮廓检测_基于OpenCV的区域分割、轮廓检测和阈值处理
  8. Java代码内容概述
  9. linux 进程占用cpu查看工具,Linux下如何查看某一进程的CPU占用率
  10. windows服务器迁到_将文件服务器及域控制器从2003迁移至Windows Server 2008 R2
  11. [Java并发编程实战] 简介
  12. python卡尔曼滤波_卡尔曼滤波+单目标追踪+python-opencv
  13. 老罗Android开发视频教程(Android入门介绍)九集集合
  14. 第十三届蓝桥杯2022各组完整真题(可评测)
  15. 做软件测试学编程的十大误区
  16. cpu天梯图2021 cpu性能排行榜2021最新版
  17. 写好英语科技论文的诀窍: 主动迎合读者期望,预先回答专家可能质疑--周耀旗教授...
  18. 为什么计算机专业的学生要学习使用 Linux 系统?
  19. html卷轴展开动画,Flash制作卷轴展开的动画
  20. html中css字体颜色设置,css样式字体设置宋体 css中font字体颜色怎么设置

热门文章

  1. TCP端口数65535的限制
  2. 软件皮肤制作工具(skinbuilder) v1.1官方版下载
  3. 使用BSRR和BRR熄灭和点亮LED灯
  4. v5系列服务器后面板不存在以下哪款指示,检查服务器 - 8100 V5 服务器 V100R005 用户指南 12 - 华为...
  5. 操作系统导论(1.0)
  6. 主板开启网络唤醒_WOL网络唤醒远程开机功能设置方法图文教程
  7. 语义检索系统【一】:基于无监督预训练语义索引召回:SimCSE、Diffcse
  8. 2022-02-17 WPF上位机 119-三菱PLC协议之MC协议
  9. 旅游景区智能分析-需求说明文档
  10. python 内置函数转list_python学习笔记11-python内置函数