UltraWinGrid:单元格添加可嵌入编辑器

来源:互联网 发布:adobe cloud mac 下载 编辑:程序博客网 时间:2024/06/11 22:04

本文转自;http://www.2cto.com/kf/201701/589747.html

嵌入式编辑器(Embeddable Editors )不仅可以作用到某一列,还可以做到单元格这一级。如下图所示:

\

实现代码如下:


1
2
3
4
5
6
7
8
9
10
11
12
DataTable t = new DataTable();
t.Columns.Add("Col_1",typeof(object));
 
t.Rows.Add(newobject[] { Color.Red });
t.Rows.Add(newobject[] {false});
t.Rows.Add(newobject[] {"Hello"});
t.Rows.Add(newobject[] { Color.Blue });
t.Rows.Add(newobject[] {true});
t.Rows.Add(newobject[] {"Goodbye"});
 
 
this.ultraGrid1.DataSource = t;

初始化UltraGrid的行:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
privatevoidultraGrid1_InitializeRow(objectsender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
    //Create the Settings Object:
    DefaultEditorOwnerSettings theSettings =newDefaultEditorOwnerSettings();
 
    //as well as the Editor Owner:
    DefaultEditorOwner theOwner =newDefaultEditorOwner(theSettings);
 
    EmbeddableEditorBase theEditor =null;
 
    objecttheValue = e.Row.Cells[0].Value;
 
    //Create an appropriate editor based on the
    //Value's Data Type:
    if(theValueisbool)
    {
        theSettings.DataType =typeof(bool);
        theEditor =newCheckEditor(theOwner);
    }
    elseif(theValue isColor)
    {
        theSettings.DataType =typeof(Color);
        theEditor =newColorPickerEditor(theOwner);
    }
    elseif(theValue isstring)
    {
        theSettings.DataType =typeof(string);
        theEditor =newEditorWithText(theOwner);
    }
 
    //Assign it to the Cell.Editor
    e.Row.Cells[0].Editor = theEditor;
}

也可以嵌入进度条对象,如图所示:

\

实现代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
privatevoidultraGrid1_InitializeLayout(objectsender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
    UltraProgressBar ultraProgressBar1 =newUltraProgressBar();
 
    ultraProgressBar1.Minimum = 0;
    ultraProgressBar1.Maximum = 100;
 
    e.Layout.Bands[0].Columns[1].EditorComponent = ultraProgressBar1;
    e.Layout.Bands[0].Columns[1].Width = 200;
 
 
}

绑定数据源

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
DataTable t = new DataTable();
 
t.Columns.AddRange(newDataColumn[]
{
    newDataColumn("工单",typeof(string)),
    newDataColumn("进度",typeof(object))
});
 
var row = t.NewRow();
row[0] = "workorder001";
row[1] = 80;
t.Rows.Add(row);
 
var row2 = t.NewRow();
row2[0] = "workorder002";
row2[1] = 30;
t.Rows.Add(row2);
 
this.ultraGrid1.DataSource = t;

此控件英文资料查询网站http://stackoverflow.com/search?q=UltraWinGrid
0 0