使用Appearance(类似预定义的样式)
this.ultraGrid1.DisplayLayout.Appearances.Add("Highlighted" );
this.ultraGrid1.DisplayLayout.Appearances["Highlighted" ].BackColor = Color.Red;
this.ultraGrid1.DisplayLayout.Appearances["Highlighted" ].BackColor = Color.White;
或者直接给预设Appearance赋值
this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.ForeColor = Color.White;
使用操作系统样式
this.ultraGrid1.UseOsThemes = DefaultableBoolean.True;
HotTrack
this.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.ColScrollRegions[0].Split(0);
this.ultraGrid1.DisplayLayout.RowScrollRegions[0].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.Appearances["Highlighted"].BackColor = Color.Red;
this.ultraGrid1.DisplayLayout.Appearances["Highlighted"].BackColor = Color.White;
this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance =
this.ultraGrid1.DisplayLayout.Appearances["Highlighted"];
this.ultraGrid1.DisplayLayout.Override.RowSelectorAppearance =
this.ultraGrid1.DisplayLayout.Appearances["Highlighted"];
--------------------------
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.Bands[0].SortedColumns.Add("Country", false, true);
this.ultraGrid1.DisplayLayout.Bands[0].SortedColumns.Add("City", false, true);
-------------------------------------------------------
this.ultraGrid1.DisplayLayout.ViewStyleBand = ViewStyleBand.OutlookGroupBy;
this.ultraGrid1.DisplayLayout.GroupByBox.Style = GroupByBoxStyle.Compact;
this.ultraGrid1.DisplayLayout.GroupByBox.Appearance.BackColor = Color.White;
this.ultraGrid1.DisplayLayout.GroupByBox.Prompt = "Drag and drop a column to group by
that 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.Band[0].CardView = true;
grid.Band[0].CardSettings..... 样式设置
展开所有行(子行)
this.ultraGrid1.Rows.ExpandAll(true);
数据过滤器
示例
e.Layout.Override.AllowRowFiltering = DefaultableBoolean.True;
e.Layout.Override.RowFilterAction = RowFilterAction.AppearancesOnly;
e.Layout.Override.FilteredInCellAppearance.ForeColor = Color.DarkGreen;
e.Layout.Override.FilteredOutCellAppearance.ForeColor = 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 filter
rows...";
this.ultraGrid1.DisplayLayout.Bands[0].SpecialRowPromptField = "Address";
the LogicalOperator property of the ColumnFiltersCollection object.
外观
ultraGrid1.DisplayLayout.Override.FilterRowAppearance
ultraGrid1.DisplayLayout.Override.FilterRowAppearanceActive
ultraGrid1.DisplayLayout.Override.FilterCellAppearance
ultraGrid1.DisplayLayout.Override.FilterRowSelectorAppearance
自定义过滤规则
UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[2];
band.ColumnFilters["Unit Price"].FilterConditions.Clear( );
band.ColumnFilters["Unit Price"].FilterConditions.Add(
FilterComparisionOperator.GreaterThan, 5 );
band.ColumnFilters["Unit Price"].FilterConditions.Add(
FilterComparisionOperator.LessThan, 10 );
band.ColumnFilters["Unit Price"].LogicalOperator = FilterLogicalOperator.And;
数据错误提示
this.ultraGrid1.DisplayLayout.Override.SupportDataErrorInfo =
SupportDataErrorInfo.RowsAndCells;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].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.Cells["Fax"].Value;
// Set the data error if Fax column value is empty
if(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);
}
Tooltip
SummarySettings averageSummary =
e.Layout.Bands[0].Summaries.Add(
"GradeAverage",
SummaryType.Average,
e.Layout.Bands[0].Columns["Grade"] );
averageSummary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
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.Bands[0].Summaries.Add(
"sum",
SummaryType.Sum,
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0],
SummaryPosition.UseSummaryPositionColumn );
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 );
AlphaBend
if(this.chkRowAlpha.Checked == true)
{
this.ultraGrid1.DisplayLayout.Override.RowAppearance.BackColorAlpha =
Alpha.UseAlphaLevel;
this.ultraGrid1.DisplayLayout.Override.RowAppearance.AlphaLevel =
short.Parse(this.spnAlphaLevel.Value.ToString());
}
else
{
this.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 + "\\Backgrounds\\nasa_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;
}
else
{
this.ultraGrid1.AlphaBlendMode = Infragistics.Win.AlphaBlendMode.Disabled;
this.ultraGrid1.DisplayLayout.Appearance.ImageBackground = null;
}
显隐标题
if (chShowCaption.Checked == true)
this.ultraGrid1.Text = "UltraWinGrid CardView Sample";
else
this.ultraGrid1.Text = "";
边框显示
ug.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
背景色
ug.DisplayLayout.Appearance.BackColor = Color.White;
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ Band ■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
设置数据条带退格宽度
this.ultraGrid1.DisplayLayout.Bands[1].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
e.Layout.Override.HeaderPlacement = HeaderPlacement.OncePerGroupedRowIsland;
e.Layout.Bands[0].Override.HeaderPlacement = HeaderPlacement.FixedOnTop;
标题换行展示
this.ultraGrid1.DisplayLayout.Override.WrapHeaderText = true;
Header置顶不动
设置displaylayout中的stationarymargins
标题行样式
this.ultraGrid1.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free;
this.ultraGrid1.DisplayLayout.Bands[0].HeaderVisible = true;
this.ultraGrid1.DisplayLayout.Bands[1].HeaderVisible = true;
this.ultraGrid1.DisplayLayout.Bands[1].Header.Caption = "Orders";
this.ultraGrid1.DisplayLayout.Bands[0].Indentation = 0;
this.ultraGrid1.DisplayLayout.Bands[1].Indentation = 0;
this.ultraGrid1.DisplayLayout.RowConnectorStyle = RowConnectorStyle.None;
this.ultraGrid1.DisplayLayout.Bands[0].Header.Appearance.ThemedElementAlpha =
Alpha.Transparent;
this.ultraGrid1.DisplayLayout.Bands[0].Header.Appearance.BackColor =
SystemColors.ActiveCaption;
this.ultraGrid1.DisplayLayout.Bands[0].Header.Appearance.ForeColor =
SystemColors.ActiveCaptionText;
this.ultraGrid1.DisplayLayout.Bands[1].Header.Appearance.ThemedElementAlpha =
Alpha.Transparent;
this.ultraGrid1.DisplayLayout.Bands[1].Header.Appearance.BackColor = Color.Blue;
this.ultraGrid1.DisplayLayout.Bands[1].Header.Appearance.BackColor2 = Color.Red;
this.ultraGrid1.DisplayLayout.Bands[1].Header.Appearance.ForeColor = Color.White;
this.ultraGrid1.DisplayLayout.Bands[1].Header.Appearance.BackGradientStyle =
GradientStyle.Horizontal;
隐藏标题行
this.UltraGrid1.Text = "";
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ Row ■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
行选择方式
e.Layout.Override.SelectTypeRow = SelectType.Single;
e.DisplayLayout.Bands["Orders"].Override.SelectTypeRow = SelectType.Extended;
e.Layout.Override.CellClickAction = 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.Bands[0].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.Rows[10];
this.ultraGrid1.ActiveRow = objRow;
this.ultraGrid1.Rows[10].Appearance.BackColor2 = Color.Blue;
this.ultraGrid1.Rows[10].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;
行高度调整
e.Layout.Override.DefaultRowHeight = 60;
e.Layout.Override.RowSizing = RowSizing.Free;
this.ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.Free;
行布局(将列分组展示)
ultraGrid1.DisplayLayout.Bands[0].Groups.Add("Name");
ultraGrid1.DisplayLayout.Bands[0].Groups.Add("Address");
ultraGrid1.DisplayLayout.Bands[0].Groups.Add("Phone");
ultraGrid1.DisplayLayout.Bands[0].Columns["CompanyName"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Name"];
ultraGrid1.DisplayLayout.Bands[0].Columns["ContactName"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Name"];
ultraGrid1.DisplayLayout.Bands[0].Columns["ContactTitle"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Name"];
ultraGrid1.DisplayLayout.Bands[0].Columns["CustomerID"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Name"];
ultraGrid1.DisplayLayout.Bands[0].Columns["Address"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Address"];
ultraGrid1.DisplayLayout.Bands[0].Columns["Country"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Address"];
ultraGrid1.DisplayLayout.Bands[0].Columns["City"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Address"];
ultraGrid1.DisplayLayout.Bands[0].Columns["Region"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Address"];
ultraGrid1.DisplayLayout.Bands[0].Columns["PostalCode"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Address"];
ultraGrid1.DisplayLayout.Bands[0].Columns["Phone"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Phone"];
ultraGrid1.DisplayLayout.Bands[0].Columns["Fax"].Group =
ultraGrid1.DisplayLayout.Bands[0].Groups["Phone"];
ultraGrid1.DisplayLayout.Bands[0].LevelCount = 2;
ultraGrid1.DisplayLayout.Bands[0].Columns["City"].Level = 1;
ultraGrid1.DisplayLayout.Bands[0].Columns["Country"].Level = 1;
ultraGrid1.DisplayLayout.Bands[0].Columns["PostalCode"].Level = 1;
ultraGrid1.DisplayLayout.Bands[0].Columns["Fax"].Level = 1;
冻结行
this.ultraGrid1.DisplayLayout.Override.FixedRowStyle = FixedRowStyle.Top;
this.ultraGrid1.Rows.FixedRows.Add(this.ultraGrid1.Rows[0]);
this.ultraGrid1.Rows[0].Fixed = true;
this.ultraGrid1.DisplayLayout.Override.FixedRowIndicator = FixedRowIndicator.Button;
FixedRowAppearance
FixedRowCellAppearance
FixedRowSelectorAppearance
统计行
this.ultraGrid1.DisplayLayout.Override.AllowRowSummaries = AllowRowSummaries.True;
this.ultraGrid1.DisplayLayout.Override.SummaryDisplayArea =
SummaryDisplayAreas.GroupByRowsFooter | SummaryDisplayAreas.TopFixed;
------------------------------------------------------
this.ultraGrid1.DisplayLayout.Bands[0].Summaries.Add(
SummaryType.Minimum,
null,
this.ultraGrid1.DisplayLayout.Bands[0].Columns["Country"],
SummaryPosition.Left,
null
);
this.ultraGrid1.DisplayLayout.Bands[0].Summaries[0].SummaryPosition =
SummaryPosition.Center;
this.ultraGrid1.DisplayLayout.Bands[0].SummaryFooterCaption = "My Sums";
行首显示行号(行选择器)
e.Layout.Override.RowSelectors = DefaultableBoolean.True;
e.Layout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex;
e.Layout.Override.RowSelectorWidth = 30;
选中行
this.ultraGrid1.Rows[i].Selected = true;
激活行
this.ultraGrid1.Rows[i].Activate();
this.ultraGrid1.ActiveRow = this.ultraGrid1.Rows[5];
this.ultraGrid1.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.Aqua;
this.ultraGrid1.ActiveCell = this.ultraGrid1.ActiveRow.Cells["CompanyName"];
遍历行
// 定位到首行
UltraGridRow aRow = this.ultraGrid1.GetRow(ChildRow.First);
// 搜索后继行
if(aRow.HasNextSibling())
{
UltraGridRow NextRow = aRow.GetSibling(SiblingRow.Next);
MessageBox.Show("Has Siblings");
}
// 搜索子行
if(aRow.HasChild())
{
UltraGridRow childRow = aRow.GetChild(Infragistics.Win.UltraWinGrid.ChildRow.First);
MessageBox.Show("Has a Child");
}
判断总行数
this.ultraGrid1.Rows.Count
特殊行外观设置
this.ultraGrid1.DisplayLayout.Override.SpecialRowSeparator =
SpecialRowSeparator.FixedRows;
this.ultraGrid1.DisplayLayout.Override.SpecialRowSeparatorHeight = 25;
this.ultraGrid1.DisplayLayout.Override.BorderStyleSpecialRowSeparator =
UIElementBorderStyle.Dashed;
隐藏行分隔线
e.Layout.Reset();
e.Layout.Override.CellAppearance.BorderAlpha = Alpha.Transparent;
e.Layout.Override.RowAppearance.BorderColor = Color.White;
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ Column ■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
UltraGrid内置支持的列编辑类型
Default 缺省类型
Edit 文本框
EditButton 按钮文本框
CheckBox 复选框
TriStateCheckBox 三态复选框
DropDown 组合框(可编辑)
DropDownList 下拉框(只选)
DropDownValidate 组合框(只可输入列表中的数据)
Button 按钮。点击时触发 ClickCellButton 事件
DropDownCalendar 下拉日历控件
Date 日期输入、下拉日历组合控件。可设置 MinValue 和 MaxValue,并对
输入进行掩码校验
DateWithoutDropDown 日期输入
DateWithSpin 类似Date控件,但用spin按钮取代了下拉日历控件
DateTime 日期时间输入控件
DateTimeWithoutDropDown 日期时间输入控件,但取消了下拉按钮
DateTimeWithSpin 日期时间输入控件,使用spin按钮替代下拉按钮
Color 色彩选择
Currency 金额,可修改 MaskInput 属性定制mask
CurrencyNonNegative 金额,不允许负数
CurrencyPositive 金额,只允许正数
Double double。可用 NumberFormatInfo 设置掩码,用 MinValue MaxValue
限制范围
DoubleWithSpin double + spin
DoubleNonNegative double 非负
DoubleNonNegativeWithSpin double 非负 spin
DoublePositive double 正数
DoublePositiveWithSpin double 正数 spin
Font 字体选择框
Image 图像展示(EmbeddableImageRenderer)
ImageWithShadow 图像,阴影效果
Integer 整数
IntegerWithSpin 整数,spin
IntegerPositive 整数,正数
IntegerPositiveWithSpin 整数,正数,spin
IntegerNonNegative 整数,非负
IntegerNonNegativeWithSpin 整数,非负,spin
Time 时间(可用MaskInput 设置掩码,用 Minimum 和 maximum 设置范围
)
TimeWithSpin 时间,spin
TimeZone 时区
URL URL(FormattedLinkEditor)
FormattedText 带格式的文本(FormattedLinkEditor)
设置列编辑类型示例
button
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Style = ColumnStyle.Button;
checkbox
this.ultraGrid1.DisplayLayout.Bands[0].Columns.Add("CheckBoxColumn");
this.ultraGrid1.DisplayLayout.Bands[0].Columns["CheckBoxColumn"].DataType = typeof
(bool);
this.ultraGrid1.DisplayLayout.Bands[0].Columns["CheckBoxColumn"].Style =
ColumnStyle.CheckBox;
dropdownlist
this.ultraGrid1.DisplayLayout.ValueLists.Add("List1");
this.ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(1, "One");
this.ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(2, "Two");
this.ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(3, "Three");
this.ultraGrid1.DisplayLayout.ValueLists["List1"].DisplayStyle =
ValueListDisplayStyle.DisplayText;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[2].Style = ColumnStyle.DropDownList;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[2].ValueList =
this.ultraGrid1.DisplayLayout.ValueLists["List1"];
手工设置单元格编辑控件
EmbeddableEditorBase editor = null;
DefaultEditorOwnerSettings editorSettings = new DefaultEditorOwnerSettings( );
---------------------------------------
EditorWithText
editorSettings.DataType = typeof( string );
editor = new EditorWithText( new DefaultEditorOwner( editorSettings ) );
ColorPickerEditor
editorSettings.DataType = typeof( Color );
editor = new ColorPickerEditor( new DefaultEditorOwner( editorSettings ) );
FontNameEditor
valueList = new ValueList( );
editorSettings.DataType = typeof( string );
for ( int i = 0; i < System.Drawing.FontFamily.Families.Length; i++ )
valueList.ValueListItems.Add( System.Drawing.FontFamily.Families[i].Name );
editorSettings.ValueList = valueList;
editor = new FontNameEditor( new DefaultEditorOwner( editorSettings ) );
---------------------------------------
EditorWithMarsk (Currency)
editorSettings.DataType = typeof( decimal );
editor = new EditorWithMask( new DefaultEditorOwner( editorSettings ) );
editorSettings.MaskInput = "$ -nn,nnn,nnn.nn";
EditorWithMask (double)
editorSettings.DataType = typeof( double );
editorSettings.MaskInput = "-nnnnnnnn.nnnn";
editor = new EditorWithMask( new DefaultEditorOwner( editorSettings ) );
EditorWithMask(integers)
editorSettings.DataType = typeof( int );
editor = new EditorWithMask( new DefaultEditorOwner( editorSettings ) );
editorSettings.MaskInput = "-nnnnnnnn";
EditorWithMask(IPv4)
editorSettings.DataType = typeof( string );
editor = new EditorWithMask( new DefaultEditorOwner( editorSettings ) );
editorSettings.MaskInput = "nnn\\.nnn\\.nnn\\.nnn";
EditorWithMask(phone numbers)
editorSettings.DataType = typeof( string );
editor = new EditorWithMask( new DefaultEditorOwner( editorSettings ) );
editorSettings.MaskInput = "(###) ###-####";
EditorWithMask (hh:mms:ss tt)
editorSettings.DataType = typeof( DateTime );
editorSettings.MaskInput = "hh:mm:ss tt";
editor = new EditorWithMask( new DefaultEditorOwner( editorSettings ) );
---------------------------------------
EditorWithCombo (Yes No dropdownlist)
editorSettings.DataType = typeof( bool );
valueList = new ValueList( );
valueList.ValueListItems.Add( true, "Yes" );
valueList.ValueListItems.Add( false, "No" );
editorSettings.ValueList = valueList;
editor = new EditorWithCombo( new DefaultEditorOwner( editorSettings ) );
EditorWithCombo (using ValueList)
valueList = new ValueList( );
valueList.ValueListItems.Add( 0, "Zero" );
valueList.ValueListItems.Add( 1, "One" );
valueList.ValueListItems.Add( 2, "Two" );
valueList.ValueListItems.Add( 3, "Three" );
valueList.ValueListItems.Add( 4, "Four" );
valueList.ValueListItems.Add( 5, "Five" );
editorSettings.ValueList = valueList;
editorSettings.DataType = typeof( int );
editor = new EditorWithCombo( new DefaultEditorOwner( editorSettings ) );
EditorWithCombo (using UltraDropDown)
// UltraDropDown : IValueList
UltraDropDown dropDown = new UltraDropDown();
dropDown.Visible = false;
dropDown.DataSource = new Record[]{
new Record("Cust 1"),
new Record("Cust 2"),
new Record("Cust 3"),
new Record("Cust 4")
};
dropDown.ValueMember = "ID"; // Cell values of this column are used as data.
dropDown.DisplayMember = "Data"; // Cell values of this column are dispalyed in the
cells.
dropDown.DisplayLayout.Override.CellAppearance.BackColor = Color.LightYellow;
dropDown.DisplayLayout.Override.CellAppearance.BackColor2 = Color.Yellow;
dropDown.DisplayLayout.Override.CellAppearance.BackGradientStyle =
GradientStyle.ForwardDiagonal;
this.Controls.Add(dropDown);
//
editorSettings.ValueList = dropDown;
editorSettings.DataType = typeof( int );
editor = new EditorWithCombo( new DefaultEditorOwner( editorSettings ) );
---------------------------------------
OptionSetEditor
editorSettings.DataType = typeof( bool );
valueList = new ValueList( );
valueList.ValueListItems.Add( true, "Yes" );
valueList.ValueListItems.Add( false, "No" );
editorSettings.ValueList = valueList;
editor = new OptionSetEditor( new DefaultEditorOwner( editorSettings ) );
---------------------------------------
CheckEditor
editorSettings.DataType = typeof( bool );
editor = new CheckEditor( new DefaultEditorOwner( editorSettings ) );
CheckEditor (ThreeState)
editorSettings.DataType = typeof( bool );
editor = new CheckEditor( new DefaultEditorOwner( editorSettings ) );
((CheckEditor)editor).ThreeState = true;
---------------------------------------
DateTimeEditor
editorSettings.DataType = typeof( DateTime );
editorSettings.MaskInput = "mm/dd/yyyy";
editor = new DateTimeEditor( new DefaultEditorOwner( editorSettings ) );
DateTimeEditor (mm/dd/yy hh:mm:ss)
editorSettings.DataType = typeof( DateTime );
editorSettings.MaskInput = "mm/dd/yy hh:mm:ss";
editor = new DateTimeEditor( new DefaultEditorOwner( editorSettings ) );
---------------------------------------
ProgressBarEditor
editorSettings.DataType = typeof( int );
editor = new Infragistics.Win.UltraWinProgressBar.ProgressBarEditor( new
DefaultEditorOwner( editorSettings ) );
设置 FieldValue 列的控件
private void ultraGrid2_InitializeRow(object sender,
Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
string fieldType = e.Row.Cells["FieldType"].Text;
EmbeddableEditorBase editor = ...
e.Row.Cells[ "FieldValue" ].Editor = editor;
}
列只读
e.Layout.Override.Rows["xxx"].CellActivation = CellActivation.NoEdit;
隐藏列
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
冻结列
this.ultraGrid1.DisplayLayout.UseFixedHeaders = true;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Header.Fixed = true;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Header.FixedHeaderIndicator =
FixedHeaderIndicator.None;
this.ultraGrid1.DisplayLayout.Override.FixedHeaderAppearance.BackColor =
Color.LightYellow;
this.ultraGrid1.DisplayLayout.Override.FixedCellAppearance.BackColor = Color.LightYellow;
this.ultraGrid1.DisplayLayout.Override.FixedCellSeparatorColor = Color.Red;
展示列分隔线
this.ultraGrid1.DisplayLayout.Override.CellAppearance.BorderColor = Color.Red;
列允许拖动和切换
this.ultraGrid1.DisplayLayout.Override.AllowColMoving = AllowColMoving.WithinBand;
this.ultraGrid1.DisplayLayout.Override.AllowColSwapping = AllowColSwapping.WithinBand;
列宽调整
e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn;
e.Layout.Override.AllowColSizing = AllowColSizing.Free;
this.ultraGrid1.DisplayLayout.Override.ColumnAutoSizeMode =
ColumnAutoSizeMode.VisibleRows;
this.ultraGrid1.DisplayLayout.Bands[1].Override.ColumnAutoSizeMode =
ColumnAutoSizeMode.AllRowsInBand;
this.ultraGrid1.Rows[0].PerformAutoSize( );
遍历列
grid.Layout.Bands[0].Columns.FromKey("Key")
foreach ( UltraGridColumn column in e.Layout.Bands[0].Columns )
column.Width = 100;
判断某列是否重复
public static bool CheckIfSame(UltraGrid ug, string colname)
{
for(int i = 0; i < ug.Rows.Count; i++)
{
for(int j = i+1; j < ug.Rows.Count; j++)
if(ug.Rows[i].Cells[colname].Text == ug.Rows[j].Cells[colname].Text &&
ug.Rows[i].Cells[colname].Text != "")
return true;
}
return false;
}
添加非绑定列
this.ultraGrid1.DisplayLayout.Bands[0].Columns.Add("CalculatedColumn", "Calculated
Value");
获取子数据条带个数
private int GetNumberofChildBands(Infragistics.Win.UltraWinGrid.UltraGridBand aBand)
{
int GetNumberofChildBands = 0;
foreach(UltraGridColumn aCol in aBand.Columns)
{
if(aCol.IsChaptered)
GetNumberofChildBands = GetNumberofChildBands + 1;
}
return GetNumberofChildBands;
}
不同值可以给以不同的颜色。
Properties-> DisplayLayout->bands->0-XXX->Columns->从弹出窗口中,选择一个列-
>ValueBaseAppearance->添加Conditions,即可。
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ Cell ■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
选中单元格样式
ug.DisplayLayout.Override.SelectedCellAppearance.BackColor = Color.SteelBlue;//选中单元格
单元格选择方式
e.Layout.Override.SelectTypeCell = SelectType.Single;
单元格格式
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
// Fit columns
e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn;
// Create culture objects
CultureInfo cultureENUS = CultureInfo.CreateSpecificCulture("en-us");
CultureInfo cultureDEDE = CultureInfo.CreateSpecificCulture("de-de");
CultureInfo cultureJAJP = CultureInfo.CreateSpecificCulture("ja-jp");
// Set date formats
e.Layout.Bands[0].Columns["OrderDate"].Format = "d";
e.Layout.Bands[0].Columns["OrderDate"].FormatInfo = cultureENUS;
e.Layout.Bands[0].Columns["RequiredDate"].Format = "d";
e.Layout.Bands[0].Columns["RequiredDate"].FormatInfo = cultureDEDE;
e.Layout.Bands[0].Columns["ShippedDate"].Format = "d";
e.Layout.Bands[0].Columns["ShippedDate"].FormatInfo = cultureJAJP;
}
文字过长的裁剪展示方式
this.ultraGrid1.DisplayLayout.Override.CellAppearance.TextTrimming =
TextTrimming.EllipsisCharacter;
修改单元格背景
void UltraGrid1_AfterCellUpdate(...)
{
if(e.Cell.Column.Key == "Column_5")
{
int cellValue = (int)e.Cell.Value;
if(cellValue == 100)
{
e.Cell.Appearance.BackColor = System.Drawing.Color.Red;
}
else
e.Cell.Appearance.BackColor = System.Drawing.Color.White;
}
}
单元格背景图片
private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellAppearance.ImageBackground =
Image.FromFile(System.IO.Path.Combine(
Application.StartupPath, @"..\..\ExtraFiles\Find in Field.bmp"));
}
单元格按钮样式
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Style = ColumnStyle.Button;
this.ultraGrid1.DisplayLayout.Override.CellButtonAppearance.Image =
Image.FromFile(System.IO.Path.Combine(
Application.StartupPath, @"..\..\ExtraFiles\Find in Field.bmp"));
this.ultraGrid1.DisplayLayout.Bands[0].Override.ButtonStyle =
UIElementButtonStyle.Button3D;
多行单元格
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].CellMultiLine =
DefaultableBoolean.True;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].VertScrollBar = true;
this.ultraGrid1.DisplayLayout.Override.DefaultRowHeight = 100;
单元格点击处理方式
this.ultraGrid1.DisplayLayout.Override.CellClickAction =
CellClickAction.EditAndSelectText;
单元格值和键
this.ultraGrid1.Rows[0].Cells["字段名"].Value // 单元格的值
cell.Column.Key // 单元格归属的列的键
this.ultraGrid1.Selected.Cells; // 被选中单元格
下拉框单元格
手工设置
在Properties-> DisplayLayout->ValueLists,添加ValueList
Properties-> DisplayLayout->bands->0-XXX->Columns->某个Column->ValueList等于新添加的
ValueList,同时设定Style是DropDown
还要再写个Event Handler,详细其他Style等等可以看这个Link:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=1708
代码设置
ValueList locValueList = this.ultraGrid.DisplayLayout.ValueLists.Add("Locs");
foreach (DataRow dr in m_ds.Tables["Loc"].Rows)
locValueList.ValueListItems.Add((int)(dr["ID"]), dr["Name"].ToString());
ultraGrid.DisplayLayout.Bands["Customer"].Columns["LocID"].ValueList =
ultraGrid.DisplayLayout.ValueLists["Locs"];
ValueList 示例
ultraGrid1.DisplayLayout.ValueLists.Add("List1");
ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(1, "One");
ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(2, "Two");
ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(3, "Three");
ultraGrid1.DisplayLayout.ValueLists["List1"].DisplayStyle =
ValueListDisplayStyle.DisplayText;
ultraGrid1.DisplayLayout.Bands[0].Columns.Add("Notes");
ultraGrid1.DisplayLayout.Bands[0].Columns["Notes"].ValueList =
this.ultraGrid1.DisplayLayout.ValueLists["List1"];
ultraGrid1.DataBind();
设置特定单元格处于编辑状态
this.ultraGrid1.ActiveCell = this.ultraGrid1.ActiveRow.Cells["CompanyName"];
this.ultraGrid1.Focus();
this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false);
合并单元格
合并具有相同值的单元格
this.ultraGrid1.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Always;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].MergedCellStyle =
MergedCellStyle.Never;
合并单元格外观设置
this.ultraGrid1.DisplayLayout.Override.MergedCellAppearance.BackColor =
Color.LightYellow;
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].MergedCellAppearance.BackColor =
Color.Blue;
合并逻辑:文本一致就可以合并
this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].MergedCellEvaluationType =
MergedCellEvaluationType.MergeSameText;
定制单元格合并逻辑
private void ultraGrid1_InitializeLayout(object sender,
Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
e.Layout.Override.MergedCellStyle = MergedCellStyle.Always;
e.Layout.Bands[0].Columns["ShippedDate"].MergedCellEvaluator = new
CustomMergedCellEvaluator();
}
public class CustomMergedCellEvaluator:
Infragistics.Win.UltraWinGrid.IMergedCellEvaluator
{
public CustomMergedCellEvaluator(){}
// 合并日期相同的单元格(无需时间精确相同)
public bool ShouldCellsBeMerged(UltraGridRow row1, UltraGridRow row2,
UltraGridColumn column)
{
DateTime date1 = (DateTime)row1.GetCellValue(column);
DateTime date2 = (DateTime)row2.GetCellValue(column);
return date1.Date == date2.Date;
}
}
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ 自定义单元格编辑控件 ■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
EmbeddableEditorBase
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■ FULL EXAMPLE ■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
//
// UltraDataColumns
//
UltraDataColumn ultraDataColumn1 = new UltraDataColumn("BidId");
UltraDataColumn ultraDataColumn2 = new UltraDataColumn("BidPaperId");
UltraDataColumn ultraDataColumn3 = new UltraDataColumn("BidCompanyName");
UltraDataColumn ultraDataColumn4 = new UltraDataColumn("BidMoney");
UltraDataColumn ultraDataColumn5 = new UltraDataColumn("ValidBidMoney");
UltraDataColumn ultraDataColumn6 = new UltraDataColumn("ValidBidRank");
UltraDataColumn ultraDataColumn7 = new UltraDataColumn("ValidBidRemark");
UltraDataColumn ultraDataColumn8 = new UltraDataColumn("MoneyScore");
UltraDataColumn ultraDataColumn9 = new UltraDataColumn("PaperScore");
UltraDataColumn ultraDataColumn10 = new UltraDataColumn("BusinessScore");
ultraDataColumn1.DataType = typeof(int);
ultraDataColumn2.DataType = typeof(int);
ultraDataColumn5.DataType = typeof(double);
ultraDataColumn8.DataType = typeof(double);
ultraDataColumn9.DataType = typeof(double);
ultraDataColumn10.DataType = typeof(double);
//
// UltraDataSource
//
this.ultraDataSource = new Infragistics.Win.UltraWinDataSource.UltraDataSource
(this.components);
this.ultraDataSource.Band.Columns.AddRange(new object[] {
ultraDataColumn1,
ultraDataColumn2,
ultraDataColumn3,
ultraDataColumn4,
ultraDataColumn5,
ultraDataColumn6,
ultraDataColumn7,
ultraDataColumn8,
ultraDataColumn9,
ultraDataColumn10});
//
// UltraGridColumns
//
UltraGridColumn ultraGridColumn1 = new UltraGridColumn("BidId");
UltraGridColumn ultraGridColumn2 = new UltraGridColumn("BidPaperId");
UltraGridColumn ultraGridColumn3 = new UltraGridColumn("BidCompanyName");
UltraGridColumn ultraGridColumn4 = new UltraGridColumn("BidMoney");
ultraGridColumn1.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
ultraGridColumn1.Header.VisiblePosition = 0;
ultraGridColumn1.Hidden = true;
ultraGridColumn2.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
ultraGridColumn2.Header.Caption = "编号";
ultraGridColumn2.Header.VisiblePosition = 1;
ultraGridColumn2.Hidden = true;
ultraGridColumn3.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
ultraGridColumn3.Header.Caption = "投标公司";
ultraGridColumn3.Header.Fixed = true;
ultraGridColumn3.Header.VisiblePosition = 2;
ultraGridColumn3.Width = 159;
ultraGridColumn4.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
ultraGridColumn4.Header.Caption = "投标金额(万元)";
ultraGridColumn4.Header.VisiblePosition = 3;
ultraGridColumn4.Width = 108;
//
// UltraGridBand
//
UltraGridBand ultraGridBand1 = new UltraGridBand("Band 0", -1);
ultraGridBand1.Columns.AddRange(new object[] {
ultraGridColumn1,
ultraGridColumn2,
ultraGridColumn3,
ultraGridColumn4
});
//
// UltraGrid
//
this.grid = new Infragistics.Win.UltraWinGrid.UltraGrid();
this.grid.DataSource = this.ultraDataSource;
this.grid.DisplayLayout.AutoFitStyle =
Infragistics.Win.UltraWinGrid.AutoFitStyle.ExtendLastColumn;