版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、XtraGrid gridview基本用法DevExpress XtraGrid的功能实在强大,刚使用的时候看到一大片属性设置,分不清东南西北,参照demo和使用中的一些经验,记录一下使用方法。现在数据库访问都使用ORM技术了,对于DataSouce绑定以下是以IList为说明对象。 控件基本定义 DevExpress.XtraGrid.GridControl gridControl1; 1、 数据绑定(IList) DevExpress.XtraGrid.Views.Grid.GridView gridView1; IList<MyClass> list = new Bindin
2、gList<MyClass>(); /初始list list.Add(A); list.Add(B); . gridControl1.DataSource = list; 2、 在Grid上编辑数据 修改属性gridView1.OptionsView.NewItemRowPosition,设为Top或Bottom可以在Grid上添加数据。 (在demo中原文:a record object must be inherited from the IEditableObject class if you need the ability to cancel newly added re
3、cords via the grid) 译:如果你需要通过gird取消新建的记录,你的记录对象必须实现IEditableObject (注:在测试中,感觉不需要继承IEditableObject,在grid编辑后也能实现取消。demo通过实现IEditableObject的BeginEdit、CancelEdit方法,数据编辑后恢复特定数据。不使用grid直接修改数据,可以考虑这种恢复原数据的方法。) 3、 修改列(Column)格式 DevExpress.XtraGrid.Columns.GridColumn col = gridView1.Columns0; 数据对齐方式 col.Appe
4、aranceCell.TextOptions.HAlignment, 默认值Default,可选值Default/Near/Center/Far。 说明:以下情况是基于从左到右的文字排列;若是从右到左,用法相反。 Default:数据默认的对齐方式 Near:左对齐 Center:居中对齐 Far:右对齐 列标题 col.Caption 对应绑定数据的属性 col.FieldName 排列顺序 col.VisibleIndex 格式化显示数据 Col.DisplayFormat.FormatType Col.DisplayFormat.Format Col.DisplayFormat.Form
5、atString 区别:FormatType/FormatString 使用当前系统的语言区域设置,Format使用特定的System.IFormatProvider设置。 (原文注释:Use the FormatType and FormatString properties to format values based on the current language and regional settings (culture). FormatType specifies the type of values to be formatted. FormatString specifies
6、a format pattern appropriate for the current FormatType value. You can refer to the Standard Numeric Format Strings and Date and Time Format Strings topics in MSDN for information on format specifiers. Setting the FormatType property changes the format provider used when formatting values by the Get
7、DisplayText function. Format providers supply mation such as the character to use as the decimal point when formatting numeric strings and the separation character to use when formatting a System.DateTime object. The Format property specifies the format provider to use. You can change the Format pro
8、perty explicitly by assigning a System.IFormatProvider object. This can be useful if you wish to format values according to a specific culture (not the current one). In this case, you also need to set the FormatType property to FormatType.Custom.) 4、 使用Grid内置导航栏 gridControl1.UseEmbeddedNativgator=Tr
9、ue 设定内置导航栏按钮其他属性 gridControl1.EmbeddedNavigator 5、 GridView内置方式编辑数据 禁止编辑数据 gridView1.OptionsBehavior.Editable = False,默认是True 可编辑。 Gridview内置数据编辑器显示方式 gridView1.OptionsBehavior.EditorShowMode,可选值Default/ MouseDown/MouseUp/ Click。 说明: Default 多选Cell相当于Click,单选Cell相当于MouseDown MouseDown 在单元格内按下鼠标键时打开内
10、置编辑器 MouseUp 在单元格内释放鼠标键时打开内置编辑器 Click 在不是编辑状态,但获得焦点的单元格中点击时打开编辑器。点击非焦点单元格时,首先会切换焦点,再点击时才打开编辑器 6、 设定GrideView单元格的内置编辑器 在Run Designer的Columns选中需要变更编辑方式的Column,在ColumnEdit 属性的下拉菜单中选择编辑数据使用的控件。 例1:Person表的CountryID字段的值来自Country表,使用下拉列表显示CountryName编辑 修改CountryIDColumn.ColumnEdit值,选new->LookupEdit,默认命
11、名为repositoryItemLookUpEdit1。展开ColumnEdit属性,将DisplayMember 设为CountryName,DropDownRows是下拉列表的行数,ValueMember设为CountryID。 代码中添加: /init data repositoryItemLookUpEdit1.DataSource = ds.TablesCountry; 例2:字段Age是整型,需要使用SpinEdit编辑 修改AgeColumn.ColumnEdit值,选new->SpinEdit。展开ColumnEdit属性,修改MaxValue、MinValue设定最大、
12、最小值。运行时Age的取值只能在MaxValue至MinValue之间选值。s 7、 GridView调节行高显示大文本 默认情况下gridview已单行方式显示,过长的文本只能显示开头部分,鼠标停留在单元格上方有ToolTip显示所有文本。在文本单元格的右边两个按钮供切换显示上下行。若需要在单元格变更行高显示所有文本。使用 gridView1.OptionsView.RowAutoHeight = True; gridView1.LayoutChanged(); 也可以通过事件判断文本内容改变行高 代码 private void gridView1_CalcRowHeight(object
13、sender,DevExpress.XtraGrid.Views.Grid.RowHeightEventArgs e) if(e.RowHandle >= 0) e.RowHeight = (int)gridView1.GetDataRow(e.RowHandle)"RowHeight" 8、 数据导出 XtraGrid支持Html、Xml、Txt、Xsl导出,对应的导出器是ExportHtmlProvider、ExportXmlProvider、ExportTxtProvider、ExportXslProvider 例:使用html格式导出数据 代码 IExport
14、Provider provider = new ExprotHtmlProvider(filename); ExportTo(provider); private void ExportTo(IExportProvider provider) Cursor currentCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; this.FindForm().Refresh(); BaseExportLink link = gridView1.CreateExportLink(provider); (link as GridVi
15、ewExportLink).ExpandAll = false; link.Progress += new DevExpress.XtraGrid.Export.ProgressEventHandler(Export_Progress);/进度条事件 link.ExportTo(true); provider.Dispose(); link.Progress -= new DevExpress.XtraGrid.Export.ProgressEventHandler(Export_Progress); Cursor.Current = currentCursor; 9、 焦点单元格显示方式 G
16、rideView默认的焦点单元格显示方式是整行选中,焦点单元格高亮。可以调整以下属性进行修改 代码 gridView1.FocusRectStyle :焦点绘画方式 默认DrawFocusRectStyle.CellFocus(单元格)/ DrawFocusRectStyle.RowFocus(行)/ DrawFocusRectStyle.None(不绘画) bool gridView1.OptionsSelection.EnableAppearanceFocusedCell :是否焦点显示选中的单元格 bool gridView1.OptionsSelection.EnableAppeara
17、nceFocusedRow :是否焦点显示选中的行 bool gridView1.OptionsSelection.InvertSelection :是否反显示 bool gridView1.OptionsSelection.MultiSelect:是否使用多选 10、 显示非数据源的数据devexpress.xtragrid.views.grid.gridview 格式化单元格分类: C# windows forms 2011-04-06 14:15 247人阅读 评论(0) 收藏 举报实现CustomColumnDisplayText事件(只能用于显示)private void bande
18、dGridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) if(e.Column.FiledName="fmapnumber") DataRow row = bandedGridView1.GetDataRow(e.RowHandle); e.DisplayText = string.Format("0","xxx"); 可以在GrideView上增加数据源没有
19、的列,如合计、日期、序号或其他数据源等。 方法一:实现CustomColumnDisplayText事件(只能用于显示) 以下例子在bandedGridColumn1上显示 FirstName+LastName 代码 bandedGridColumn1.OptionsColumn.AllowEdit = false; private void bandedGridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) if(e.
20、Column.Equals(bandedGridColumn1) DataRow row = bandedGridView1.GetDataRow(e.RowHandle); e.DisplayText = string.Format("0 1", row"FirstName", row"LastName"); 方法二: 设定列的UnboundType,并实现CustomUnboundColumnData事件(可修改值) 以下例子演示DateTime/Int/String 绑定到数据列上显示。当修改 GrideView上的值时,将修改
21、同步到原数组中。 代码 bandedGridColumn4.UnboundType = DevExpress.Data.UnboundColumnType.DateTime; bandedGridColumn5.UnboundType = DevExpress.Data.UnboundColumnType.Integer; bandedGridColumn6.UnboundType = DevExpress.Data.UnboundColumnType.String; private void bandedGridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) if(array = null) return; if(e.ListSourceRowIndex >= array.Count) return; Record rec = arraye.ListSourceRowIndex as Record; if(rec = null) return; switch(e.Column.UnboundType) case UnboundColumnType.Date
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 影像AI算法的透明度与可解释性要求
- 2025年固体废物处理服务合同协议
- 康复机器人数据泄露的风险防控策略
- 康复启动时间与DVP预防的相关性
- 帕金森病基因编辑与深部脑刺激微创协同策略
- 川崎病冠状动脉瘤合并高血压的干预策略
- 医疗器械法规与监管
- 护理岗位护理岗位护理设备操作
- 居家血液净化患者的管理策略
- 局部复发与远处转移喉癌的治疗策略差异
- 2026年日历表(含农历 全年共有365天)
- “正则动量”解决带电粒子在磁场中的运动问题
- 家用电器事故案例分析与警示
- 少儿培训机构策划书
- 吟诵古诗课程设计
- 中国慢性冠脉综合征患者诊断及管理指南2024版解读
- 第30讲 ZD6转辙机课件讲解
- (正式版)SHT 3551-2024 石油化工仪表工程施工及验收规范
- Unit7CareersLesson1EQIQ课文长难句分析课件-高中英语北师大版2019选择性
- YY0778-2018《射频消融导管》标准变化解读
- 船舶货运保险理赔答疑手册
评论
0/150
提交评论