Skip to Content
0

Grouped header Columns for Grid or Matrix

Nov 02, 2016 at 04:09 PM

654

avatar image

I am using the C# UI API 9.2 for SAP and would like to make grouped headers for our table. Do Matrix/Grid or both support this? How can I do this with code?

What I want to achieve is headers with sub headers below them.

c# | ui | uiapi
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member Nov 03, 2016 at 05:32 AM
1

Hi Szabolcs,

There is a MergeCell method in the CommonSetting object of a Matrix. You can use that to merge cells and achieve the above effect.

oMatrix.CommonSetting.MergeCell(row, col, true);

There is more information about the MergeCell method in the SDK Help Center.

Pedro Magueija

LinkedIn | Twitter | Blog

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Does the Matrix object has some way to edit the Headers? The Grid has the `oGrid.RowHeaders`, not sure that would allow the merging of cells though. Also I serialized a Matrix as XML and did not found nodes regarding the Headers.

<Matrix>
    <AffectsFormMode>1</AffectsFormMode>
    <BackColor>-1</BackColor>
    <Description></Description>
    <DisplayDesc>0</DisplayDesc>
    <Enabled>1</Enabled>
    <FontSize>-1</FontSize>
    <ForeColor>-1</ForeColor>
    <FromPane>0</FromPane>
    <Height>498</Height>
    <Layout>0</Layout>
    <Left>11</Left>
    <LinkTo></LinkTo>
    <RightJustified>0</RightJustified>
    <TextStyle>0</TextStyle>
    <Top>124</Top>
    <ToPane>0</ToPane>
    <Type>127</Type>
    <UniqueID>frk_m1</UniqueID>
    <Visible>1</Visible>
    <Width>745</Width>
    <ColumnsInfo>
        <ColumnInfo>
            <AffectsFormMode>1</AffectsFormMode>
            <BackColor>-1</BackColor>
            <ChooseFromListAlias></ChooseFromListAlias>
            <ChooseFromListUID></ChooseFromListUID>
            <DataBind/>
            <Description></Description>
            <DisplayDesc>0</DisplayDesc>
            <Editable>1</Editable>
            <FontSize>-1</FontSize>
            <ForeColor>-1</ForeColor>
            <RightJustified>0</RightJustified>
            <TextStyle>0</TextStyle>
            <Title>#</Title>
            <Type>16</Type>
            <UniqueID>#</UniqueID>
            <ValidValues/>
            <ValOFF>N</ValOFF>
            <ValON>Y</ValON>
            <Visible>1</Visible>
            <Width>25</Width>
        </ColumnInfo>
        <ColumnInfo>
            <AffectsFormMode>1</AffectsFormMode>
            <BackColor>-1</BackColor>
            <ChooseFromListAlias></ChooseFromListAlias>
            <ChooseFromListUID></ChooseFromListUID>
            <DataBind/>
            <Description></Description>
            <DisplayDesc>0</DisplayDesc>
            <Editable>1</Editable>
            <FontSize>-1</FontSize>
            <ForeColor>-1</ForeColor>
            <RightJustified>0</RightJustified>
            <TextStyle>0</TextStyle>
            <Title>Col_0</Title>
            <Type>16</Type>
            <UniqueID>Col_0</UniqueID>
            <ValidValues/>
            <ValOFF>N</ValOFF>
            <ValON>Y</ValON>
            <Visible>1</Visible>
            <Width>50</Width>
        </ColumnInfo>
        <ColumnInfo>
            <AffectsFormMode>1</AffectsFormMode>
            <BackColor>-1</BackColor>
            <ChooseFromListAlias></ChooseFromListAlias>
            <ChooseFromListUID></ChooseFromListUID>
            <DataBind/>
            <Description></Description>
            <DisplayDesc>0</DisplayDesc>
            <Editable>1</Editable>
            <FontSize>-1</FontSize>
            <ForeColor>-1</ForeColor>
            <RightJustified>0</RightJustified>
            <TextStyle>0</TextStyle>
            <Title></Title>
            <Type>16</Type>
            <UniqueID>Col1</UniqueID>
            <ValidValues/>
            <ValOFF>N</ValOFF>
            <ValON>Y</ValON>
            <Visible>1</Visible>
            <Width>20</Width>
        </ColumnInfo>
        <ColumnInfo>
            <AffectsFormMode>1</AffectsFormMode>
            <BackColor>-1</BackColor>
            <ChooseFromListAlias></ChooseFromListAlias>
            <ChooseFromListUID></ChooseFromListUID>
            <DataBind/>
            <Description></Description>
            <DisplayDesc>0</DisplayDesc>
            <Editable>1</Editable>
            <FontSize>-1</FontSize>
            <ForeColor>-1</ForeColor>
            <RightJustified>0</RightJustified>
            <TextStyle>0</TextStyle>
            <Title></Title>
            <Type>16</Type>
            <UniqueID>Col2</UniqueID>
            <ValidValues/>
            <ValOFF>N</ValOFF>
            <ValON>Y</ValON>
            <Visible>1</Visible>
            <Width>20</Width>
        </ColumnInfo>
    </ColumnsInfo>
    <Rows>
        <Row>
            <Visible>1</Visible>
            <Columns>
                <Column>
                    <ID>#</ID>
                    <Value></Value>
                </Column>
                <Column>
                    <ID>Col_0</ID>
                    <Value></Value>
                </Column>
                <Column>
                    <ID>Col1</ID>
                    <Value></Value>
                </Column>
                <Column>
                    <ID>Col2</ID>
                    <Value></Value>
                </Column>
            </Columns>
        </Row>
    </Rows>
</Matrix>


0
Former Member
Szabolcs Kelemen

Hi Szabolcs,

RowHeaders is the 1st column (usually the #), Column Titles are the 1st row on the top where you can usually double-click to sort.

So the RowHeaders are in fact showing in your XML (ID #).

You can edit the Column Titles in a matrix too, but it's done on a column level.

matrix.Columns.Item("columnId").TitleObject

It's fairly limited though as you can only change the Title and the Sortable property.

Pedro Magueija

LinkedIn | Twitter | Blog

0

I am not sure, the Row object on the XML is only there, because I added a row with oMatrix.AddRows(1). If I skip that, the Rows node is empty.

</ColumnsInfo>
    <Rows></Rows>
</Matrix>

So, I have no idea how to add another Header row and merge some cells of the original row (just as in the image I posted).

I tried with this code:

Columns oColumns = null;
            Column oColumn = null;
           
            Matrix oMatrix = (Matrix)oForm.Items.Item(ID_MATRIX_MAIN).Specific;

            oColumn = oMatrix.Columns.Add("#", BoFormItemTypes.it_EDIT);
            oColumn.TitleObject.Caption = "#";
            oColumn.Editable = false;

            oColumn = oMatrix.Columns.Add("Col1",BoFormItemTypes.it_EDIT);
            oColumn.Editable = true;
            oColumn.TitleObject.Sortable = true;
            oColumn.TitleObject.Caption = "Col1";

            oColumn = oMatrix.Columns.Add("Col2", BoFormItemTypes.it_EDIT);
            oColumn.Editable = true;
            oColumn.TitleObject.Sortable = false;
            oColumn.TitleObject.Caption = "Col2";

            //oForm.DataSources.UserDataSources.Add("Col1", BoDataType.dt_SHORT_TEXT);
            //oForm.DataSources.UserDataSources.Add("Col2", BoDataType.dt_SHORT_TEXT);

            //oMatrix.SelectRow(1,false,false);
            oMatrix.CommonSetting.MergeCell(0, 1, true);

            string xml = oMatrix.SerializeAsXML(BoMatrixXmlSelect.mxs_All);
            Console.Write("");
0
Former Member
Szabolcs Kelemen

Hi Szablocs,

Apparently, MergeCell doesn't work in the Column Titles.

You'll have to add two rows and use those as your Title and sub title.

It will also show the empty native column title (I didn't find any way to hide it).

Here is an example with code:

form = b1.Application.Forms.Add("tmp"); 
form.Height = 500;
form.Width = 500;
 
var datatable = form.DataSources.DataTables.Add("dt");
datatable.Columns.Add("1", BoFieldsType.ft_AlphaNumeric, 254);
datatable.Columns.Add("2", BoFieldsType.ft_AlphaNumeric, 254);
datatable.Columns.Add("3", BoFieldsType.ft_AlphaNumeric, 254);
datatable.Columns.Add("4", BoFieldsType.ft_AlphaNumeric, 254);
 
datatable.Rows.Add(4);
 
datatable.SetValue("1", 0, "Caption 1");
datatable.SetValue("2", 0, "");
datatable.SetValue("3", 0, "Caption 2");
datatable.SetValue("4", 0, "");
 
datatable.SetValue("1", 1, "Sub Caption 1");
datatable.SetValue("2", 1, "Sub Caption 2");
datatable.SetValue("3", 1, "Sub Caption 3");
datatable.SetValue("4", 1, "Sub Caption 4");
 
for (int i = 2; i < 4; i++)
{
 datatable.SetValue("1", i, "lorem");
 datatable.SetValue("2", i, "ipsum");
 datatable.SetValue("3", i, "dolore");
 datatable.SetValue("4", i, "sit");
}
 
var item = form.Items.Add("grid", BoFormItemTypes.it_GRID);
item.Height = 400;
item.Width = 400;
 
var grid = item.Specific as Grid;
grid.DataTable = datatable;
 
for (int c = 0; c < grid.Columns.Count; c++)
{
 grid.Columns.Item(c).TitleObject.Caption = string.Empty;
}
 
grid.CommonSetting.MergeCell(1, 0, true);
grid.CommonSetting.MergeCell(1, 2, true);
 
grid.CommonSetting.SetRowEditable(1, false);
grid.CommonSetting.SetRowEditable(2, false);
 
grid.AutoResizeColumns();
form.Visible = true;

Here's how it looks:

Pedro Magueija

LinkedIn | Twitter | Blog

merged-cells.png (22.6 kB)
1

Looks like this would solve it. Do you think it is possible to put Sortable on a Sub Caption Column's ? If it is a Column header, it is easy with oColumn.TitleObject.Sortable.

Thanks!

0