资源描述
UltraGrid操作UltraGrid 是Infragistics netadvanage 控件库中提供的一个Windows 网格控件,功能强大,完全可以取代VS 中提供的GridView控件。参考提供商首页:术语persist 持续化(保存)property 属性attribute 特性setting 设置Band 数据条带示例图片一、UltraGrid 的基本概念UltraGrid的属性设计和一般的控件颇为不同。理解其设计思想,有助于你从其浩瀚的属性中快速找到你所需要的东西。在此文中WinGrid, UltraGrid, UltraWinGrid 是同一个东西。WinGrid是一个可展示层级数据的网格控件数据源实现IList 或ITypedList 接口就可以展示(但不一定可以增删)可展现具有层级关系的数据,如customers - orders - order detailsWinGrid 功能:排序过滤统计行列大小调整冻结列和冻结行列托拽调整位置列互换位置分割视图 Outlook风格的BroupBy功能(用户可将列拖到分组栏中对数据进行分组)卡片视图数据行的自定义布局单元格可使用多种编辑控件导出到Excel打印其它Infragistics Presentation Layer Framework 的公共特性,如:Apperances, DrawFilters, CreationFiltersWinGrid 数据条带和层级数据UltraGrid 可表现具有层级关系的数据每个层级的数据用一个band(数据条带)来描述每个band 具有若干的column 和row,类似DataTable层级间的关系用外键关联来描述WinGrid 的外观样式方案(1)使用Appearance 对象控制控件的外观和样式设置WinGrid 控件的外观并不直接设置其字体背景颜色等属性而是创建或者选择现有的Appearance 对象(类似Web的css class样式)该Appearance 对象拥有多种格式相关的属性,如对齐方式、字体、颜色、图像和alpha融合信息该方式有以下好处:缩减了代码的数量便于控制统一的外观,只需要改Appearance 对象就可以了对于Grid 这样具有众多子元素的控件,使用此方式设置外观可有效减少内存消耗(2)其布局和外观是可持续化保存的UltraGrid.DisplayLayout 属性(UltraGridLayout类)作为所有可持续化保存的特性和对象的容器调用该对象的Load(), Save(), LoadFromXml(), SaveAsXml() 函数可存取外观控制由于大部分UltraGrid的设置都可以持续化,所以大部分的功能都是通过UltraGridLayout对象进行设置的(3)样式是可从上级控件继承和重载的若控件设置其Appearance 为Default,该控件将会继承其父控件的样式设置(而不是什么缺省值)如缺省状态下,cell 使用row的背景色,而row使用band的背景色Band 对象默认继承上级对象的样式,而使用Override 属性(UltraGridOverride 类)来设置其特殊属性WinGrid 决定绘制一个对象的外观和行为时先检查该对象的Override属性若该属性内的值被明确修改(非Default),则使用该值否则使用上级对象相应的值(Default)大部分的属性即可以直接在WinGrid设置,也可以在Band设置,后者会覆盖前者/ 例:默认只能单行选择,而orders band 允许选择多行using Infragistics.Win.UltraWinGrid;UltraGrid1.DisplayLayout.Override.SelectTypeRow = SelectType.Single;UltraGrid1.DisplayLayout.BandsOrders.Override.SelectTypeRow = SelectType.Extended;卡片视图(Card View)每条记录用一张卡片来展示,类似表单视图卡片视图的限制只能展现最底层的band数据,无法再展示其子层的数据无法增加新记录?设置方法grid.Band0.CardView = true;grid.Band0.CardSettings. 样式设置分组视图(GroupBy View)类似outlook 2007,可将列拖到分组栏中,让数据分组展示操作方法:grid.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;二、UltraGrid 设计器操作UltraWinGrid Designer(UltraGrid设计器项目)Basic Settings :Data Schema : 设置绑定列的数据格式Presets : 从预设中选择一个样式,有三种类型:(1)仅与外观相关;(2)仅与行为相关;(3)两者都有Manage Presets : 预设管理和设置Feature Picker : 配置功能。详见后Appearance Browser : 定制的一些外观样式Band and Column Settings : 要展示数据集和列设置Band0 - Band 0 :Columns : 展示列设置:Data Schema中定义绑定列,非绑定列Column Arrangement Overview : 列展示位置设置(类似报表设计器)Column Arrangement Designer : 分两种:Row layout(可用于复杂表头设置),Group and levelsControl Settings : 控件所有的属性设置。其实上面的所有设置都可以在这里找到,只是层次深不易找。详见下。Feature Picker(UltraGrid功能设置)AutoFit Style : 列自动适应宽度CardView : 卡片视图Column Moving : 列是否可拖动位置Column Sizing : 列调整宽度的方式Column Swapping : 是否允许列交换位置Empty Rows : 是否展示空行,空行的样式Filtering : 列过滤器Fixed Headers : 冻结列Fixed Rows : 冻结行Header Click Sort Action : 标题列点击排序方式:单列排序& 多列方式IDataErrorInfo Support : 数据错误验证方式Merged Cell : ?合并单元格Outlook Group By : Outlook Group 风格(可由用户定制数据分组)Row Selectors : 行选择符号(一个小箭头)Row Siziing : 行调整高度的方式Scrolling : 滚动条样式Selection : 行列单元格选择方式Summaries : 统计单元格Updating : 是否允许数据行增删改Control Setting(UltraGrid控件设置特有属性)AppearanceBehaviorDataDesignLayoutDiaplayLayoutAddNewBoxAutoFitStyleBandsEnmptyRowSettingsOverrideAllowAddNewAllowDeleteAllowUpdateRowSizingViewStyle : SingleBand | MultiBand杂项常用操作添加Column: StartBasic SettingsData SchemaManually Define a Schema添加Column,命名用数据库中的字段名。添加Column Title: Band and Column SettingsBand 0(手动添加Column后)Columns选择列Header修改Caption属性排序:Picker/Filtring/Allow分组:Picker/OutLook GroupBy/Active编辑:Picker/Update多行表头:Column Arrangement Designer/Add Group/Add Level/把相应的列拖到组下面,隐藏列:Column Arrangement Designer/Show Hide单列不可编辑:Band0/Column/cellactivation 设置成NoEdit单击单元格选择状态:Band0/Column/CellClickAction单元格编辑控件:Band0/Column/EditorControl单元格合并:Band0/Column/MergedCell。冻结列:Picker/Fixed Header三、UltraGrid 外观控制 Grid 动态转载样式文件this.ultraGrid1.ApplyPresetFromXml(C:Program FilesCommon FilesInfragistics + PresetsWinUltraGridBaseStandardFlatGreen.xml, true);存取布局文件(可用这玩意设计报表,动态载入)this.ultraGrid1.DisplayLayout.SaveAsXml(WinGridLayout.xml);this.ultraGrid1.DisplayLayout.LoadFromXml( ath,.ExtraFilesWinGridLayout.xml);使用Appearance(类似预定义的样式)this.ultraGrid1.DisplayLayout.Appearances.Add(Highlighted );this.ultraGrid1.DisplayLayout.AppearancesHighlighted .BackColor = Color.Red;this.ultraGrid1.DisplayLayout.AppearancesHighlighted .BackColor = Color.White;或者直接给预设Appearance赋值this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.White;使用操作系统样式 = DefaultableBoolean.True;HotTrackthis.ultraGrid1.DisplayLayout.Override.HotTrackCellAppearance.BackColor = Color.Blue; this.ultraGrid1.DisplayLayout.Override.HotTrackRowCellAppearance.BackColor =Color.Yellow;this.ultraGrid1.DisplayLayout.Override.HotTrackHeaderAppearance.BackColor =Color.Blue;this.ultraGrid1.DisplayLayout.Override.HotTrackRowAppearance.ForeColor =Color.LightGreen;this.ultraGrid1.DisplayLayout.Override.HotTrackRowSelectorAppearance.BackColor = Color.Green;分割滚动视图设置分割视图(创建SplitBar)this.ultraGrid1.DisplayLayout.ColScrollRegions0.Split(0);this.ultraGrid1.DisplayLayout.RowScrollRegions0.Split(200);取消分割视图this.ultraGrid1.DisplayLayout.MaxColScrollRegions = 1;this.ultraGrid1.DisplayLayout.MaxRowScrollRegions = 1;修改Tab键功能this.ultraGrid1.DisplayLayout.TabNavigation = TabNavigation.NextControl;TabletPC Ink-Enable将UltraInkProvider 组件拖到窗体上就可以了编辑状态的输入框右侧会显示一个小笔按钮,点击后就会弹出手写输入框若要在非TabletPC上使用该功能,需要安装TabletPC SDK定义和应用外观样式this.ultraGrid1.DisplayLayout.Appearances.Add(Highlighted);this.ultraGrid1.DisplayLayout.AppearancesHighlighted.BackColor = Color.Red;this.ultraGrid1.DisplayLayout.AppearancesHighlighted.BackColor = Color.White;this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance =this.ultraGrid1.DisplayLayout.AppearancesHighlighted;this.ultraGrid1.DisplayLayout.Override.RowSelectorAppearance =this.ultraGrid1.DisplayLayout.AppearancesHighlighted;-this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.Red;this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.White;this.ultraGrid1.DisplayLayout.Override.RowSelectorAppearance.BackColor = Color.Red;this.ultraGrid1.DisplayLayout.Override.RowSelectorAppearance.ForeColor = Color.White; GroupBy 视图this.ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;this.ultraGrid1.DisplayLayout.Bands0.SortedColumns.Add(Country, false, true);this.ultraGrid1.DisplayLayout.Bands0.SortedColumns.Add(City, false, true);-this.ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;this.ultraGrid1.DisplayLayout.GroupByBox.Style = this.ultraGrid1.DisplayLayout.GroupByBox.Appearance.BackColor = Color.White;this.ultraGrid1.DisplayLayout.GroupByBox.Prompt = Drag and drop a column to group bythat column.;this.ultraGrid1.DisplayLayout.GroupByBox.PromptAppearance.ForeColor = Color.Maroon;this.ultraGrid1.DisplayLayout.GroupByBox.BorderStyle = UIElementBorderStyle.InsetSoft;this.ultraGrid1.DisplayLayout.GroupByBox.ButtonBorderStyle =UIElementBorderStyle.RaisedSoft;this.ultraGrid1.DisplayLayout.GroupByBox.ShowBandLabels = ShowBandLabels.All;this.ultraGrid1.DisplayLayout.GroupByBox.BandLabelBorderStyle =UIElementBorderStyle.Solid;this.ultraGrid1.DisplayLayout.GroupByBox.BandLabelAppearance.BackColor =Color.DarkBlue;this.ultraGrid1.DisplayLayout.GroupByBox.BandLabelAppearance.ForeColor =Color.LightYellow;this.ultraGrid1.DisplayLayout.GroupByBox.ButtonConnectorStyle =UIElementBorderStyle.Dotted;this.ultraGrid1.DisplayLayout.GroupByBox.ButtonConnectorColor = Color.Maroon;卡片视图grid.Band0.CardView = true;grid.Band0.CardSettings. 样式设置展开所有行(子行)this.ultraGrid1.Rows.ExpandAll(true);数据过滤器示例 = DefaultableBoolean.True; = RowFilterAction.AppearancesOnly; = Color.DarkGreen; = Color.DarkRed;打开过滤器this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.True;设置过滤器功能this.ultraGrid1.DisplayLayout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;this.ultraGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;this.ultraGrid1.DisplayLayout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnLeaveCell;this.ultraGrid1.DisplayLayout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.DoesNotContain;this.ultraGrid1.DisplayLayout.Override.FilterOperandStyle =FilterOperandStyle.DropDownList;this.ultraGrid1.DisplayLayout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;this.ultraGrid1.DisplayLayout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;this.ultraGrid1.DisplayLayout.Override.FilterClearButtonLocation = FilterClearButtonLocation.Row;this.ultraGrid1.DisplayLayout.Override.FilterRowPrompt = Click here to filterrows.;this.ultraGrid1.DisplayLayout.Bands0.SpecialRowPromptField = Address;the LogicalOperator property of the ColumnFiltersCollection object.外观ultraGrid1.DisplayLayout.Override.FilterRowAppearanceultraGrid1.DisplayLayout.Override.FilterRowAppearanceActiveultraGrid1.DisplayLayout.Override.FilterCellAppearanceultraGrid1.DisplayLayout.Override.FilterRowSelectorAppearance自定义过滤规则UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands2;band.ColumnFiltersUnit Price.FilterConditions.Clear( );band.ColumnFiltersUnit Price.FilterConditions.Add(FilterComparisionOperator.GreaterThan, 5 );band.ColumnFiltersUnit Price.FilterConditions.Add( FilterComparisionOperator.LessThan, 10 );band.ColumnFiltersUnit Price.LogicalOperator = FilterLogicalOperator.And;数据错误提示this.ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo = SupportDataErrorInfo.RowsAndCells;this.ultraGrid1.DisplayLayout.Bands0.Columns0.SupportDataErrorInfo =DefaultableBoolean.False;this.ultraGrid1.DisplayLayout.Override.DataErrorCellAppearance.BackColor = Color.Red;this.ultraGrid1.DisplayLayout.Override.DataErrorRowSelectorAppearance.BackColor = Color.Red;this.ultraGrid1.DisplayLayout.Override.DataErrorRowAppearance.BackColor =Color.LightYellow;private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)string rowError = ;string cellError = ;Object value = e.Row.CellsFax.Value;/ Set the data error if Fax column value is emptyif(DBNull.Value = value)rowError = Row contains errors.;cellError = Fax can not be empty;DataRowView drv = (DataRowView)e.Row.ListObject;drv.Row.RowError = rowError;drv.Row.SetColumnError(Fax, cellError);TooltipSummarySettings averageSummary =GradeAverage,SummaryType.Average, );averageSummary.SummaryPosition = averageSummary.SummaryPositionColumn = averageSummary.SourceColumn; averageSummary.DisplayFormat = Average: 0:.#;averageSummary.Band.Override.SummaryFooterCaptionVisible = DefaultableBoolean.False; averageSummary.Band.Override.BorderStyleSummaryFooter = UIElementBorderStyle.None;-SummarySettings summary =this.ultraGrid1.DisplayLayout.Bands0.Summaries.Add(sum,SummaryType.Sum,this.ultraGrid1.DisplayLayout.Bands0.Columns0, );summary.ToolTipText = string.Format( Sum of column 0.,summary.SourceColumn.Header.Caption );this.ultraGrid1.Rows.SummaryValues sum .ToolTipText = string.Format( Sum of column 0., summary.SourceColumn.Header.Caption );AlphaBendif(this.chkRowAlpha.Checked = true)this.ultraGrid1.DisplayLayout.Override.RowAppearance.BackColorAlpha =this.ultraGrid1.DisplayLayout.Override.RowAppearance.AlphaLevel =short.Parse(this.spnAlphaLevel.Value.ToString();elsethis.ultraGrid1.DisplayLayout.Override.RowAppearance.BackColorAlpha =Alpha.Opaque;this.ultraGrid1.DisplayLayout.Override.RowAppearance.AlphaLevel = 0;-if (chEnableAlphaBlending.Checked)this.ultraGrid1.DisplayLayout.Appearance.ImageBackground =Image.FromFile(clsSamplesPath.GraphicsPath +Backgroundsnasa_saturn_montage.jpg);this.ultraGrid1.DisplayLayout.Appearance.ImageBackgroundOrigin =Infragistics.Win.ImageBackgroundOrigin.Form;this.ultraGrid1.DisplayLayout.Appearance.ImageBackgroundStyle =Infragistics.Win.ImageBackgroundStyle.Tiled;this.ultraGrid1.AlphaBlendMode = Infragistics.Win.AlphaBlendMode.Optimized;elsethis.ultraGrid1.AlphaBlendMode = Infragistics.Win.AlphaBlendMode.Disabled;this.ultraGrid1.DisplayLayout.Appearance.ImageBackground = null;显隐标题if (chShowCaption.Checked = true)this.ultraGrid1.Text = UltraWinGrid CardView Sample;elsethis.ultraGrid1.Text = ;边框显示ug.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;背景色ug.DisplayLayout.Appearance.BackColor = Color.White; Band 设置数据条带退格宽度this.ultraGrid1.DisplayLayout.Bands1.Indentation = 100; Caption 表格标题(Caption)this.ultraGrid1.DisplayLayout.CaptionVisible = DefaultableBoolean.True;标题ug.DisplayLayout.CaptionAppearance.TextHAlign = Infragistics.Win.HAlign.Left;ug.DisplayLayout.CaptionAppearance.BackColor = Color.LightSteelBlue; Head 控制标题行的位置/ RepeatOnBreak, FixedOnTop, OncePerRowIsland, OncePerGroupedRowIsland = HeaderPlacement.OncePerGroupedRowIsland; = HeaderPlacement.FixedOnTop;标题换行展示this.ultraGrid1.DisplayLayout.Override.WrapHeaderText = true;Header置顶不动设置displaylayout中的stationarymargins标题行样式this.ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free;this.ultraGrid1.DisplayLayout.Bands0.HeaderVisible = true;this.ultraGrid1.DisplayLayout.Bands1.HeaderVisible = true;this.ultraGrid1.DisplayLayout.Bands1.Header.Caption = Orders;this.ultraGrid1.DisplayLayout.Bands0.Indentation = 0;this.ultraGrid1.DisplayLayout.Bands1.Indentation = 0;this.ultraGrid1.DisplayLayout.RowConnectorStyle = RowConnectorStyle.None;this.ultraGrid1.DisplayLayout.Bands0.Header.Appearance.ThemedElementAlpha =Alpha.Transparent;this.ultraGrid1.DisplayLayout.Bands0.Header.Appearance.BackColor = SystemColors.ActiveCaption;this.ultraGrid1.DisplayLayout.Bands0.Header.Appearance.ForeColor = SystemColors.ActiveCaptionText;this.ultraGrid1.DisplayLayout.Bands1.Header.Appearance.ThemedElementAlpha =Alpha.Transparent;this.ultraGrid1.DisplayLayout.Bands1.Header.Appearance.BackColor = Color.Blue; this.ultraGrid1.DisplayLayout.Bands1.Header.Appearance.BackColor2 = Color.Red; this.ultraGrid1.DisplayLayout.Bands1.Header.Appearance.ForeColor = Color.White; this.ultraGrid1.DisplayLayout.Bands1.Header.Appearance.BackGradientStyle =GradientStyle.Horizontal;隐藏标题行this.UltraGrid1.Text = ; Row 行选择方式 = SelectType.Single;e.DisplayLayout.BandsOrders.Override.SelectTypeRow = SelectType.Extended; = CellClickAction.RowSelect;选择行样式ug.DisplayLayout.Override.SelectedRowAppearance.BackColor = Color.SteelBlue;交错行样式this.ultraGrid1.DisplayLayout.Override.RowAlternateAppearance.BackColor = Color.Red; 激活行样式this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.Red;ug.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.SteelBlue;添加行操作提示private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e) this.ultraGrid1.DisplayLayout.Bands0.AutoPreviewEnabled = true;private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)e.Row.Description = Row Description;private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)this.ultraGrid1.DisplayLayout.ActiveRow.Description =Data changed in this row will not be added to the database + until you press the Update button.;行渐变背景UltraGridRow objRow = this.ultraGrid1.Rows10;this.ultraGrid1.ActiveRow = objRow;this.ultraGrid1.Rows10.Appearance.BackColor2 = Color.Blue;this.ultraGrid1.Rows10.Appearance.BackGradientStyle = GradientStyle.Circular;修改特殊行的位置新增行this.ultraGrid1.DisplayLayout.Override.AllowAddNew = AllowAddNew.TemplateOnTop;this.ultraGrid1.DisplayLayout.Override.SequenceFixedAddRow = 2;过滤行this.ultraGrid1.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.True;this.ultraGrid1.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow;this.ultraGrid1.DisplayLayout.Override.SequenceFilterRow = 1;统计行this.ultraGrid1.DisplayLayout.Override.AllowRowSummaries = AllowRowSummaries.True;this.ultraGrid1.DisplayLayout.Override.SummaryDisplayArea = SummaryDisplayAreas.Top;this.ultraGrid1.DisplayLayout.Override.SequenceSummaryRow = 3;行高度调整 = 60; = RowSizing.Free;this.ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.Free;行布局(将列分组展示)ultraGrid1.DisplayLayout.Bands0.Groups.Add(Name);ultraGrid1.DisplayLayout.Bands0.Groups.Add(Address);ultraGrid1.DisplayLayout.Bands0.Groups.Add(Phone);ultraGrid1.DisplayLayout.Bands0.ColumnsCompanyName.Group =ultraGrid1.DisplayLayout.Bands0.GroupsName;ultraGrid1.DisplayLayout.Bands0.ColumnsContactName.Group =ultraGrid1.DisplayLayout.Bands0.GroupsName;ultraGrid1.DisplayLayout.Bands0.ColumnsContactTitle.Group =ultraGrid1.DisplayLayout.Bands0.GroupsName;ultraGrid1.DisplayLayout.Bands0.ColumnsCustomerID.Group =ultraGrid1.DisplayLayout.Bands0.GroupsName;ultraGrid1.DisplayLayout.Bands0.ColumnsAddress.Group =ultraGrid1.DisplayLayout.Bands0.GroupsAddress;ultraGrid1.DisplayLayout.Bands0.ColumnsCountry.Group =ultraGrid1.DisplayLayout.Bands0.GroupsAddress;ultraGrid1.DisplayLayout.Bands0.ColumnsCity.Group =ultraGrid1.DisplayLayout.Bands0.GroupsAddress;ultraGrid1.DisplayLayout.Bands0.ColumnsRegion.Group =ultraGrid1.Disp
展开阅读全文