Ahmar
Ahmar

Reputation: 1

Janus GridEX - C# How to show multi-line header using columnsets at runtime?

I have already tried: How to wrap header caption in Janus GridEx and https://www.c-sharpcorner.com/forums/table-column-set and looked through Janus documentation at http://codelibraries.blogspot.com/search/label/Janus%20GridEX.

I have a business requirement to show wrapped column header. For example, if column header is:

This is column header

need to show

This is column
header

As it is right now (before I tried implementing code for this requirement), code looked like:

        dgMulti.SetDataBinding(bulkTable, "")
        dgMulti.RetrieveStructure()

        Dim column As Janus.Windows.GridEX.GridEXColumn
        For Each column In dgMulti.RootTable.Columns
            column.Width = 150
        Next

where bulkTable is a System.Data.DataTable object.

After visiting above links, I tried suggestions and used ColumnSets as shown below and added after above code:

        Dim CSET As New Janus.Windows.GridEX.GridEXColumnSet()
        CSET.Caption = "YourCaption"
        CSET.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center
        CSET.ColumnCount = 2
        CSET.Width = 150
        CSET.Key = "YourCaptionKey"
        ' FOLLOWING LINE THROW ERROR 
        **CSET.Add(New Janus.Windows.GridEX.GridEXColumn(dgMulti.RootTable.Columns(0).Key, dgMulti.RootTable.Columns(0).ColumnType), 0, 1)
        CSET.Add(New Janus.Windows.GridEX.GridEXColumn(dgMulti.RootTable.Columns(1).Key, dgMulti.RootTable.Columns(1).ColumnType), 0, 2)**
        dgMulti.RootTable.ColumnSets.Add(CSET)
        dgMulti.RootTable.ColumnSetHeaderLines = 2
        dgMulti.RootTable.CellLayoutMode = Janus.Windows.GridEX.CellLayoutMode.UseColumnSets

Error: Operation is not valid due to the current state of the object.

Can you please help what I am missing? I believe I need to somehow link the columns with ColumnSets but how?

Upvotes: 0

Views: 1217

Answers (2)

Thành Nguyễn
Thành Nguyễn

Reputation: 1

Dim CSET As New Janus.Windows.GridEX.GridEXColumnSet()
    CSET.Caption = "YourCaption"
    CSET.HeaderAlignment = Janus.Windows.GridEX.TextAlignment.Center
    CSET.ColumnCount = 2
    CSET.Width = 150
    CSET.Key = "YourCaptionKey"
    dgMulti.RootTable.ColumnSets.Add(CSET)
    CSET.Add(dgMulti.RootTable.Columns.Add("Yourcolumnkey"), 0, 0)
    CSET.Add(dgMulti.RootTable.Columns.Add("Yourcolumnkey"), 0, 1)
    dgMulti.RootTable.ColumnSetHeaderLines = 2
    dgMulti.RootTable.CellLayoutMode = Janus.Windows.GridEX.CellLayoutMode.UseColumnSets

Upvotes: 0

Phil Sayers
Phil Sayers

Reputation: 193

You don't need columnsets for this. I can't get a deeplink to the janus forums thread with this answer, but here is the copy/pasted answer:

You can put a CR Character if you can determine where to wrap. in e.g.

Column.Caption = Now.ToString("ddd" & vbCr & "d MMM");

You can see the janus support forums here: https://www.janusys.com. Click through to the Winforms GridEX forum, and use search phrase "wrap". The website is basically unusable in Firefox, I fallback to Chrome to browse.

Upvotes: 0

Related Questions