abraXus
  • abraXus
  • Advanced Member Topic Starter
2020-06-09T05:17:45Z
I cannot seem to get this working, so i created a test form just to see if I was missing something.
It works just fine with SpanRows set to the default value.

I have included very short code (VB.NET) placed on the Form_Load event with a default IGrid to illustrate the problem.


        IGrid1.Rows.Count = 10
        IGrid1.Header.Rows.Count = 5
        IGrid1.Cols.Count = 10
        IGrid1.Header.Cells(0, 2).TextFormatFlags = iGStringFormatFlags.DirectionVertical
        IGrid1.Header.Cells(0, 2).SpanRows = 4
        IGrid1.Header.Cells(0, 2).Value = "this is long value for a vertical header cell"
        IGrid1.Rows.AutoHeight()

I tried things in a different order and that made no difference. Please advise...
Igor/10Tec
2020-06-09T15:53:27Z
First, the last statement calls the AutoHeight() method for the collection of rows with NORMAL cells but not header cells. The most appropriate call would be IGrid1.Header.AutoHeight().

However, this does not help in the case of header cells merged vertically. Know why? Because iGrid simply does not know how to 'spread' the height of the merged cell between its rows.

Think about this problem in general. If you have a grid with merged cells (many cells merged in any directions various ways), can you provide an algorithm that can be used to adjust the row heights?
Igor/10Tec
2020-06-10T16:09:00Z
abraXus, can you post a screenshot of the grid you want to implement with iGrid.NET? It would help us a lot to understand what you need and how your grid should look.

Eventually the requested feature can be implemented using the existing members of iGrid - such as iGHdrRow.Height we can use to read/set the height of every header row.
abraXus
  • abraXus
  • Advanced Member Topic Starter
2020-06-10T22:03:09Z
Thanks for the reply.

I can work around it by manually setting the header row height in the case where it happens in my actual program, so it's not the end of the world, but it just would be nice if it worked as I expected.

Here is a screenshot of what it looks like WITH the "Up to 1 dia" column added, which has a category called "Holes" - this works fine.

Working

You can see the columns to the right of it do not have a category, so in that case i increase SpanRows by one to fill up that space, and that works nicely.

But when that column is absent, and none of the other columns have a category, it turns into this:

Grid 2

Those still visible here are technically spanning two header rows using the exact same code as the first screenshot, but they dont autosize right.

Hopefully that is enough information. As I said, it's not the end of the world, I can work around it.

btw, great product (assuming you are involved in its creation) I plan on buying it very soon.


Igor/10Tec
2020-06-11T14:49:08Z
Firs of all, thank you for your purchase of the product. It's always pleasure to know that our products really help others :)

Yes, I am the developer of iGrid, and you can discuss the details of the implementation with me.

The main problem with the iGrid header is that actually it does not have its own height. The height of this area is the sum of heights of its rows. The header of your grid has at least 4 rows. We can calculate the resulting height of the whole header based on the sizes of texts in its cells (even merged vertically and/or horizontally), but who can tell us how to 'spread' this overall height on the existing rows? Can anybody build a universal algorithm that works properly in all possible cases of merging?

As for your particular grid, have you ever thought about indicating holes in a column another way? Say, with a color or icon but not with a special header cell that appears/disappears? Perhaps, the structure of your header would be simpler then, which could help you to simplify your algorithm of row height calculation.

But in any case, the task looks very interesting and appealing for a programmer's mind 🙂
abraXus
  • abraXus
  • Advanced Member Topic Starter
2020-07-01T17:01:36Z
Now that the header rows support the IsCellPartClipped property, I can use it to determine if any of the heights that were set by the AutoHeight method need to be adjusted.

Here is a short example of how I handled it. I have variables at the top to adjust in order to debug it. It seems to work for the most part, but it seems like it needs some adjustment depending on which row the text is in, and how many rows it spans (using those variables).

Perhaps you could find a way to improve my code? If not, I can use this as-is and call it "good enough". Maybe it will even give you some ideas on a way to handle it so AutoHeight will work as I expect it to, but I will not hold my breath. :)

Public Class Form1
    ' change this to select which row has the text (and will be adjusted)
    Dim iTextRow As Integer = 2
    ' change this to set how many rows it spans
    Dim iSpanRows As Integer = 4

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        IGrid1.Rows.Count = 5
        IGrid1.Cols.Count = 5
        IGrid1.Header.Rows.Count = 7
        IGrid1.Header.Cells(iTextRow, 1).TextFormatFlags = iGStringFormatFlags.DirectionVertical
        IGrid1.Header.Cells(iTextRow, 2).TextFormatFlags = iGStringFormatFlags.DirectionVertical

        IGrid1.Header.Cells(iTextRow, 1).Value = "short"
        IGrid1.Header.Cells(iTextRow, 2).SpanRows = iSpanRows
        IGrid1.Header.Cells(iTextRow, 2).Value = "this is long value for a vertical header cell"
        IGrid1.Header.Cells(iTextRow, 3).Value = "short text"
        IGrid1.Cols.AutoWidth()
        IGrid1.Rows.AutoHeight()

        ' note that the AutoHeight did not handle the
        ' height of the spanned header row the way i was hoping
        ' so i can click the button to fix it

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' this would probably work better if I made sure the font size is the same in both
        ' but for this example they are both using the default font
        ' not sure if there might be other factors to consider
        ' create a hidden grid used for figuring out text size
        ' note there is no SpanRows used in the hidden grid
        Dim ig As New iGrid : ig.Cols.Count = 1 : ig.Rows.Count = 1
        ig.Header.Cells(0, 0).TextFormatFlags = IGrid1.Header.Cells(iTextRow, 2).TextFormatFlags

        ' scan the selected header row for clipping issue
        For iCol As Integer = 0 To IGrid1.Cols.Count - 1
            If IGrid1.Header.Cells(iTextRow, iCol).IsCellPartClipped(iGClippedCellParts.Text) Then

                ' determine height needed using the hidden grid
                ig.Header.Cells(0, 0).Value = IGrid1.Header.Cells(iTextRow, iCol).Value
                ig.Rows.AutoHeight()
                Dim newHeight As Integer = ig.Header.Rows(0).Height

                ' subtract the height of rows above it that it spans
                For iRow = iTextRow + 1 To IGrid1.Header.Cells(iTextRow, iCol).SpanRows
                    newHeight -= IGrid1.Header.Rows(iRow).Height
                Next

                ' change the height if it is not tall enough
                If IGrid1.Header.Rows(iTextRow).Height < newHeight Then
                    IGrid1.Header.Rows(iTextRow).Height = newHeight
                End If

            End If
        Next
    End Sub

End Class