如何在运行时将标题和子标题添加到网格中

时间:2014-02-16 09:21:27

标签: c# c#-4.0 grid janus

我是一个janous网格,我设置在运行时,我需要添加标题和子标题到网格。 和标题包含两部分,一部分字段,另一部分字段。 任何人都可以解释如何去做。

enter image description here

我使用C#windows表单应用程序;

        Col = new UltraGridColumn();
        Col.Caption = "Row";
        Col.Width = 10;
        Col.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center;
        Col.Key = "Row";
        Col.DataMember = "Row";
        MyGrid.Columns.Add(Col);

        Col = new UltraGridColumn();
        Col.Caption = "Name";
        Col.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center;
        Col.Key = "Name";
        Col.DataMember = "Name";
        MyGrid.Columns.Add(Col);

        Col = new UltraGridColumn();
        Col.Caption = "Family";
        Col.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center;
        Col.Key = "Family";
        Col.DataMember = "Family";
        MyGrid.Columns.Add(Col);

        Col = new UltraGridColumn();
        Col.Caption = "Address";
        Col.Key = "Address";
        Col.Width = MyGrid.Width * 18 / 100;
        Col.DataMember = "Address";
        Col.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center;
        MyGrid.Columns.Add(Col);

        Col = new UltraGridColumn();
        Col.Caption = "Tel";
        Col.Key = "Tel";
        Col.Width = 0;
        Col.DataMember = "Tel";
        Col.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center;
        MyGrid.Columns.Add(Col);

1 个答案:

答案 0 :(得分:0)

您可以使用GridEXColumnSet类按照您希望的方式对列进行分组。

这是代码段:

Janus.Windows.GridEX.GridEXColumnSet CS = new Janus.Windows.GridEX.GridEXColumnSet();
CS.Caption = "Department";
CS.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center;
CS.ColumnCount = 2;
CS.Width = 200;
CS.Key = "Department";
MyGrid.RootTable.ColumnSets.Add(CS);

然后您可以这样添加列:

CS.Add(col1, 0, 0); // First parameter is GridEXColumn, Second is row in ColumnSet, third is col
CS.Add(col2, 0, 2);