版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、2021/3/9http:/1DeVExpress控件入门简介简介: XtraEditors Library是专门为可视化的Studio.NET设计的最优化的一套100的C#控件 XtraEdiotors Library是一款具有革命性的超过20种数据编辑控制的控件它是国内第一个适合于.NET框架类型的控件。2021/3/9http:/2准备工作1.DevExpress控件的安装2.Demo查看3.帮助文档使用2021/3/9http:/3一:与.net基本的控件比较1:命名空间(NameSpace).net基本控件的类都在System.Windows.Forms的命名控件下DevExpres
2、s的控件类在DevExpress命名空间下2021/3/9http:/42:可以代替.net的控件DevExpress的大部分控件都已可以代码.net的基本控件。如:文本框:System.Windows.Forms.TextBox - DevExpress.XtraEditors.TextEdit按钮:System.Windows.Forms.Button - DevExpress.XtraEditors.SimpleButton下拉框:System.Windows.Forms.ComboBox - DevExpress.XtraEditors.ComboBoxEdit2021/3/9http
3、:/5日 期:System.Windows.Forms.DateTimePicker - DevExpress.XtraEditors.DateEdit/DevExpress.XtraEditors.TimeEdit复选框System.Windows.Forms.CheckBox - DevExpress.XtraEditors.CheckEdit这里就不一一列举了,认真看看,相信一定找出很多可以替代的控件2021/3/9http:/6二:几个比较重要、常用的属性1:EditValue DevExpress.XtraEditors.*Edit的控件都不可少的一个EditValue属性。如:De
4、vExpress.XtraEditors.*Edit 通常,EditValue会跟Text的值是一样的。只是EditValue的类型为Object,Text的属性为String,也就是EditValue通常可以代替Text属性。2:Enable和Visable 是否禁用和是否可见2021/3/9http:/73:Properties设置控件一些特征DevExpress.XtraEditors.TextEdit txt=.;例:是否只读txt.Properties.ReadOnly=true;不允许获得焦点txt.Properties.AllowFocused = false;不允许空值输入tx
5、t.Properties.AllowNullInput=true;/当这个属性应用在TimeEdit中,它的清除按钮,将会禁用(灰掉)2021/3/9http:/8禁止编辑器输入如: ComboBoxEdit c=.; c.Properties.TextEditStyle=DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;/只选模式,不能输入文本2021/3/9http:/94:Appearance设置风格。Dexpress把所有设置控件风格的特性都放到Appearance属性下。例:DevExpress.Xtra
6、Editors.SimpleButton btn=.;btn.Appearance.ForeColor = Color.Red;/前景色btn.Appearance.BackColor = Color.Red;/背景色2021/3/9http:/10 Appearance.TextOptions文本对齐操作例:btn.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;/居中对齐btn.Appearance.TextOptions.WordWrap = DevExpress.Utils.WordWr
7、ap.Wrap;/自动换行。当控件的宽度容不下文本的长度,会自动换行。注意,在某些控件中Apperarance是在Properties属性下的如:DevExpress.XtraEditors.TextEdit txt=.;txt.Properties.Appearance.ForeColor = Color.Red;2021/3/9http:/11三:几个常用的控件1:用强大的LookUpEdit代替ComboBox 1.1 ComboBox不支持数据绑定2.1 由于DevExpress的ComboBox天生的数据绑定缺陷,所以有时我们要做数据绑定,不得不使用下“功能过剩”的LooUpEdit
8、。如下代码,可用实现一个ComboBox:2021/3/9http:/12 /禁止文本输入禁止文本输入 this.lookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; /默认为默认为null的显示的显示 this.lookUpEdit1.Properties.NullText = 请选择类别请选择类别; /加入一个显示列加入一个显示列 this.lookUpEdit1.Properties.Columns.Add(new DevExpres
9、s.XtraEditors.Controls.LookUpColumnInfo(Name); this.lookUpEdit1.Properties.ShowHeader=false;/不显示页眉(包括列头)不显示页眉(包括列头) this.lookUpEdit1.Properties.ShowFooter = false;/不显示页脚(包括关闭按钮)不显示页脚(包括关闭按钮) this.lookUpEdit1.Properties.DisplayMember = Name;/要显示的字段要显示的字段,Text获得获得 this.lookUpEdit1.Properties.ValueMemb
10、er = Value;/实际值的字段实际值的字段,EditValue获获得得 /数据绑定数据绑定 ICollection list = Global.ClassCategoryList; this.lookUpEdit1.Properties.DataSource = list;/绑定数据绑定数据 this.lookUpEdit1.Properties.DropDownRows =list.Count;/设置行数设置行数(根据这个自根据这个自动设置高度动设置高度)2021/3/9http:/13 2:GridControlGridControl可以代替.net的System.Windows.F
11、orms.DataGrid控件。GirdControl只是一个容器控件,必须要求GridView视图作为它的子控件。GridControl可以包含多个视图,可以实现视图的切换。每个视图必须包含列(Column)GridControl支持层级视图2021/3/9http:/14GridControl常设置属性常设置属性 使用导航器使用导航器 this.gridControl1.UseEmbeddedNavigator = true; this.gridControl1.EmbeddedNavigator.Buttons.Append.Visible = false; this.gridContr
12、ol1.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.But
13、tons.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.grid
14、Control1.EmbeddedNavigator.Buttons.PrevPage.Visible = true;2021/3/9http:/15GridView常设置属性常设置属性 this.gridView1.OptionsBehavior.Editable = false;/禁止编辑禁止编辑 this.gridView1.OptionsCustomization.AllowFilter = false;/不允许使用不允许使用过滤过滤 this.gridView1.OptionsCustomization.AllowSort = false;/不允许使用排不允许使用排序序 this.g
15、ridView1.OptionsView.ShowGroupPanel = false;/不显示组面板不显示组面板 this.gridView1.OptionsView.ColumnAutoWidth =true;/如果宽度溢出,如果宽度溢出,自动出现滚动条自动出现滚动条 this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;/禁止单元格获得焦点禁止单元格获得焦点 this.gridView1.Appearance.SelectedRow.BackColor = Color.Transparent;/选择的行背景
16、透明选择的行背景透明2021/3/9http:/16 事件事件/订阅行焦点改变事件订阅行焦点改变事件this.gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(this.gridView1_FocusedRowChanged);/验证编辑器(单元格)值输入验证编辑器(单元格)值输入this.gridView1.ValidatingEditor += new DevExpress.XtraEditors.Controls.BaseContainerVali
17、dateEditorEventHandler(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 = 产品名称不能为空产品名称不能为空
18、; e.Valid = false; 2021/3/9http:/17/订阅设置行风格事件订阅设置行风格事件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.GetRowCellValu
19、e(e.RowHandle, 中止中止); if (value!=null&(bool)value) e.Appearance.ForeColor = Color.Red; 2021/3/9http:/18this.gridView1.CustomColumnDisplayText += new DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventHandler(this.gridView1_CustomColumnDisplayText);private DataTable _CategoryList;public D
20、ataTable 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; 2021/3/9http:/19/行单元格对齐行单元格对齐this.gr
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论