1 委托
this.ultraGrid1.AfterCellUpdate -= new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_AfterCellUpdate);
this.ultraGrid1.Rows[0].Cells["字段名"].Value = "";
this.ultraGrid1.AfterCellUpdate += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_AfterCellUpdate);
2 判断
e.Cell.Column.Key == "字段名"
3 判断某列是否重复
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;
}
4 Enter切换,在form_load事件里写
this.ultraGrid1.KeyActionMappings.Add(new Infragistics.Win.UltraWinGrid.GridKeyActionMapping(System.Windows.Forms.Keys.Enter, Infragistics.Win.UltraWinGrid.UltraGridAction.NextCell, Infragistics.Win.UltraWinGrid.UltraGridState.IsCheckbox, Infragistics.Win.UltraWinGrid.UltraGridState.Cell, 0, 0));
5 选中一行
this.ultraGrid1.Rows[i].Activate();
this.ultraGrid1.Rows[i].Selected = true;
6 新增一行,并将新行设为当前行
第一种:
Infragistics.Win.UltraWinGrid.UltraGridRow row = UltraGrid1.Rows.TemplateAddRow;
UltraGrid1.ActiveRow = row;
第二种
Infragistics.Win.UltraWinGrid.UltraGridRow row = UltraGrid1.Rows.Band.AddNew();
UltraGrid1.ActiveRow = row;
7 接受UltraGrid中编辑的值
UltraGrid1.UpdateData();
8 UltraGrid 删除选中的行
if (ug_list.ActiveRow != null)
{
if (MessageBox.Show("确定要删除选定行吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
ug_list.DeleteSelectedRows(true);
}
}
9。添加Column
Start/Basic Settings/Data Schema/Manually Define a Schema/添加Column,命名用数据库中的字段名。
10。添加Column中文名称
Band and Column Settings/Band [0](手动添加Column后)/Columns/选择列/Header/修改Caption属性
11。整个表的属性在Basic Settings或职能按钮中修改;单列的属性在Band中修改。
12。Basic Settings中Data Schema用于设置数据列;Presets用于调整样式;Picker用于定义一些选项属性。
5。绑定数据
this.ultraGrid1.DataSource = myDataSet.Tables[0];
数据列也可以在DataTable中设定,Column[0].ColumnName或Column[0].Caption
13。Header换行
智能按钮/Wrap Header Text 设为true,默认为不换行的
14。排序:Picker/Filtring/Allow
15。分组:Picker/OutLook GroupBy/Active
16。编辑:Picker/Update
17。多行表头:Column Arrangement Designer/Add Group/Add Level/把相应的列拖到组下面,
18。隐藏列:Column Arrangement Designer/Show Hide
19。单列不可编辑:Band[0]/Column/AllowEdit
20。单击单元格选择状态:Band[0]/Column/CellClickAction
21。绑定控件:Band[0]/Column/EditorControl
22。单元格合并:Band[0]/Column/MergedCell。。。
23。定住不滚动列:Picker/Fixed Header
24。增加行:
this.ultraGrid1.Rows.Band.AddNew();
this.ultraGrid1.Rows[this.ultraGrid1.Rows.Count - 1].Cells["REC_ID"].Value = CommomFun.GetID();
25。删除行:
if (this.ultraGrid1.Rows.Count <= 0)
{
MessageInfo.ShowMessage("m_system_client_0009");
return ;
}
#endregion
if (this.ultraGrid1.ActiveRow != null)
{
this.ultraGrid1.ActiveRow.Selected = true;
}
if (MessageInfo.ShowMessage("m_system_client_0003", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
bool blnDeleted = false;
for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
{
if (this.ultraGrid1.Rows[i].Selected || this.ultraGrid1.Rows[i].IsActiveRow)
{
if (this.ultraGrid1.Rows[i].Delete(false))
{
i--;
}
blnDeleted = true;
}
}
if (!blnDeleted)
{
MessageInfo.ShowMessage("m_system_client_0009");
}
}
26 UltraGrid风格设置函数
public static void ColorGrid(ref Infragistics.Win.UltraWinGrid.UltraGrid ug)
{
//标题
ug.DisplayLayout.CaptionAppearance.TextHAlign = Infragistics.Win.HAlign.Left;
ug.DisplayLayout.CaptionAppearance.BackColor = Color.LightSteelBlue;
//边框显示
ug.DisplayLayout.BorderStyle = Infragistics.Win.UIElementBorderStyle.Solid;
//背景色
ug.DisplayLayout.Appearance.BackColor = Color.White;
//默认颜色设置
ug.DisplayLayout.Override.HeaderAppearance.BackColor = Color.LightSteelBlue;//列
ug.DisplayLayout.Override.RowSelectorAppearance.BackColor = Color.LightSteelBlue;//行
//选中颜色设置
ug.DisplayLayout.Override.SelectedCellAppearance.BackColor = Color.SteelBlue;//选中单元格
ug.DisplayLayout.Override.SelectedRowAppearance.BackColor = Color.SteelBlue;//选中行
//ActiveRowx颜色设置
ug.DisplayLayout.Override.ActiveRowAppearance.BackColor = Color.SteelBlue;
}
27 UltraGrid 删除选中的行
this.ultraGrid1.DeleteSelectedRows(false);
28 委托
this.ultraGrid1.AfterCellUpdate -= new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_AfterCellUpdate);
this.ultraGrid1.Rows[0].Cells["字段名"].Value = "";
this.ultraGrid1.AfterCellUpdate += new Infragistics.Win.UltraWinGrid.CellEventHandler(this.ultraGrid1_AfterCellUpdate);
29 格子的属性
e.Cell.Column.Key :字段名
e.Cell.Column.Header.Caption :字段标题名
e.Cell.column.Band.Key :Band(表)的名称;
30 判断某列是否重复
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;
}
31 Enter切换,在form_load事件里写
this.ultraGrid1.KeyActionMappings.Add(new Infragistics.Win.UltraWinGrid.GridKeyActionMapping(System.Windows.Forms.Keys.Enter, Infragistics.Win.UltraWinGrid.UltraGridAction.NextCell, Infragistics.Win.UltraWinGrid.UltraGridState.IsCheckbox, Infragistics.Win.UltraWinGrid.UltraGridState.Cell, 0, 0));
32 选中一行
this.ultraGrid1.Rows[i].Activate();
this.ultraGrid1.Rows[i].Selected = true;
33 空行
是否显示空行this.UltraGrid1.DisplayLayout.EmptyRowSettings.ShowEmptyRows = true;
空行样式
EmptyRowStyle style = (EmptyRowStyle)this.ultraComboEditorStyle.Value;
this.UltraGrid1.DisplayLayout.EmptyRowSettings.Style = style;
34.保存属性设置
this.gridOne.DisplayLayout.Save(objLayout1,Infragistics.Win.UltraWinGrid.PropertyCategories.All);
35 重置属性设置
this.gridOne.DisplayLayout.Load(this.m_objFancyLayout, Infragistics.Win.UltraWinGrid.PropertyCategories.All);
36.不同行样式
this.gridRowProperties.DisplayLayout.Override.RowAlternateAppearance.BackColor = Color.Cyan;
this.gridRowProperties.DisplayLayout.Override.RowAlternateAppearance.ForeColor = Color.DarkBlue;
37.下拉框UltraDropDown
this.UltraDropDown1.ValueMember = "ProductID";
this.UltraDropDown1.DisplayMember = "Name";
this.ultraGrid1.DisplayLayout.Bands[0].Columns["ProductID"].ValueList = this.UltraDropDown1