欢迎来到天天文库
浏览记录
ID:37905670
大小:47.00 KB
页数:10页
时间:2019-06-02
《XtraGrid gridview基本用法》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、XtraGridgridview基本用法DevExpressXtraGrid的功能实在强大,刚使用的时候看到一大片属性设置,分不清东南西北,参照demo和使用中的一些经验,记录一下使用方法。现在数据库访问都使用ORM技术了,对于DataSouce绑定以下是以IList为说明对象。控件基本定义DevExpress.XtraGrid.GridControlgridControl1;1、数据绑定(IList)DevExpress.XtraGrid.Views.Grid.GridViewgridView1;IListlist=newBindingList2、yClass>();//初始listlist.Add(A);list.Add(B);………..gridControl1.DataSource=list;2、在Grid上编辑数据修改属性gridView1.OptionsView.NewItemRowPosition,设为Top或Bottom可以在Grid上添加数据。(在demo中原文:arecordobjectmustbeinheritedfromtheIEditableObjectclassifyouneedtheabilitytocancelnewlyaddedrecordsviathegrid)译:如果你需要通过3、gird取消新建的记录,你的记录对象必须实现IEditableObject(注:在测试中,感觉不需要继承IEditableObject,在grid编辑后也能实现取消。demo通过实现IEditableObject的BeginEdit、CancelEdit方法,数据编辑后恢复特定数据。不使用grid直接修改数据,可以考虑这种恢复原数据的方法。)3、修改列(Column)格式DevExpress.XtraGrid.Columns.GridColumncol=gridView1.Columns[0];数据对齐方式col.AppearanceCell.TextOptions.4、HAlignment,默认值Default,可选值Default/Near/Center/Far。说明:以下情况是基于从左到右的文字排列;若是从右到左,用法相反。Default:数据默认的对齐方式Near:左对齐Center:居中对齐Far:右对齐列标题col.Caption对应绑定数据的属性col.FieldName排列顺序col.VisibleIndex格式化显示数据Col.DisplayFormat.FormatTypeCol.DisplayFormat.FormatCol.DisplayFormat.FormatString区别:FormatType/Form5、atString使用当前系统的语言区域设置,Format使用特定的System.IFormatProvider设置。(原文注释:UsetheFormatTypeandFormatStringpropertiestoformatvaluesbasedonthecurrentlanguageandregionalsettings(culture).FormatTypespecifiesthetypeofvaluestobeformatted.FormatStringspecifiesaformatpatternappropriateforthecurrentFormatT6、ypevalue.YoucanrefertotheStandardNumericFormatStringsandDateandTimeFormatStringstopicsinMSDNforinformationonformatspecifiers.SettingtheFormatTypepropertychangestheformatproviderusedwhenformattingvaluesbytheGetDisplayTextfunction.Formatproviderssupplyinforwww.baiyuewang.netmationsuchasth7、echaractertouseasthedecimalpointwhenformattingnumericstringsandtheseparationcharactertousewhenformattingaSystem.DateTimeobject.TheFormatpropertyspecifiestheformatprovidertouse.YoucanchangetheFormatpropertyexplicitlybyassigningaSystem.IFormatProviderobject.Thiscanbeusefulifyouwi
2、yClass>();//初始listlist.Add(A);list.Add(B);………..gridControl1.DataSource=list;2、在Grid上编辑数据修改属性gridView1.OptionsView.NewItemRowPosition,设为Top或Bottom可以在Grid上添加数据。(在demo中原文:arecordobjectmustbeinheritedfromtheIEditableObjectclassifyouneedtheabilitytocancelnewlyaddedrecordsviathegrid)译:如果你需要通过
3、gird取消新建的记录,你的记录对象必须实现IEditableObject(注:在测试中,感觉不需要继承IEditableObject,在grid编辑后也能实现取消。demo通过实现IEditableObject的BeginEdit、CancelEdit方法,数据编辑后恢复特定数据。不使用grid直接修改数据,可以考虑这种恢复原数据的方法。)3、修改列(Column)格式DevExpress.XtraGrid.Columns.GridColumncol=gridView1.Columns[0];数据对齐方式col.AppearanceCell.TextOptions.
4、HAlignment,默认值Default,可选值Default/Near/Center/Far。说明:以下情况是基于从左到右的文字排列;若是从右到左,用法相反。Default:数据默认的对齐方式Near:左对齐Center:居中对齐Far:右对齐列标题col.Caption对应绑定数据的属性col.FieldName排列顺序col.VisibleIndex格式化显示数据Col.DisplayFormat.FormatTypeCol.DisplayFormat.FormatCol.DisplayFormat.FormatString区别:FormatType/Form
5、atString使用当前系统的语言区域设置,Format使用特定的System.IFormatProvider设置。(原文注释:UsetheFormatTypeandFormatStringpropertiestoformatvaluesbasedonthecurrentlanguageandregionalsettings(culture).FormatTypespecifiesthetypeofvaluestobeformatted.FormatStringspecifiesaformatpatternappropriateforthecurrentFormatT
6、ypevalue.YoucanrefertotheStandardNumericFormatStringsandDateandTimeFormatStringstopicsinMSDNforinformationonformatspecifiers.SettingtheFormatTypepropertychangestheformatproviderusedwhenformattingvaluesbytheGetDisplayTextfunction.Formatproviderssupplyinforwww.baiyuewang.netmationsuchasth
7、echaractertouseasthedecimalpointwhenformattingnumericstringsandtheseparationcharactertousewhenformattingaSystem.DateTimeobject.TheFormatpropertyspecifiestheformatprovidertouse.YoucanchangetheFormatpropertyexplicitlybyassigningaSystem.IFormatProviderobject.Thiscanbeusefulifyouwi
此文档下载收益归作者所有