Troy
  • Troy
  • Newbie Topic Starter
2018-11-21T02:45:25Z
Hi. I have this code in my Query_Close of a form which has a grid on it called "iGridComposite":

    Dim lCol As Long
    For lCol = 1 To Me.iGridComposite.ColCount
        Me.iGridComposite.ColVisible(lCol) = True
    Next lCol
    '
    ' Save column settings
    SaveSetting "Demo_Restore_Layout", "LayoutStrings", "Col", Me.iGridComposite.LayoutCol
    Call Log("Closing form" & frmPortfolioDiversification.iGridComposite.LayoutCol)
The For loop is an attempt to force all columns visible before I save the settings - just for troubleshooting this issue. For the record, I can see all the columns before I run this code. I do not hide any columns in my code.

I then save the settings and then immediately log those settings into a text log file.

I then open my log file and I see this:

引用:

0:15:41 PM: Closing form
1|Width|20|1|Order|1|1|Visible|1|2|Width|54|2|Order|2|2|Visible|1|3|Width|193|3|Order|4|3|Visible|1|4|Width|256|4|Order|5|4|Visible|1|
5|Width|42|5|Order|6|5|Visible|1|6|Width|30|6|Order|7|6|Visible|1|7|Width|35|7|Order|3|7|Visible|1|8|Width|37|8|Order|10|8|Visible|1|
9|Width|90|9|Order|11|9|Visible|1|10|Width|115|10|Order|12|10|Visible|1|11|Width|83|11|Order|13|11|Visible|1|12|Width|99|12|Order|14|12|Visible|1|
13|Width|77|13|Order|15|13|Visible|1|14|Width|96|14|Order|16|14|Visible|1|15|Width|97|15|Order|17|15|Visible|1|16|Width|71|16|Order|18|16|Visible|1|
17|Width|48|17|Order|19|17|Visible|1|18|Width|88|18|Order|8|18|Visible|1|19|Width|61|19|Order|9|19|Visible|1|


Note that all columns show Visible|1|

I also log the layoutcol string just after I perform the GetSetting function and it does not match what was saved. The form initialization code is below - pretty straight forward.

    '
    ' Composite Grid
    With frmPortfolioDiversification.iGridComposite
        .BeginUpdate
        .Header.UseXPStyles = False
        .Header.BackColor = RGB(43, 57, 144)
        .Header.ForeColor = RGB(255, 255, 255)
        .Editable = False
        .AllowSorting = False
        .Header.DragCols = True
        .UseXPStyles = False
        .Header.Font.Bold = True
        .Header.Flat = False
        .AddCol sheader:="  "   ' 1
        .AddCol sheader:="Account"   ' 2
        .AddCol sheader:="Acct. Type"   ' 3
        .AddCol sheader:="Client Name"   ' 4
        .AddCol sheader:="Equity"   ' 5
        .AddCol sheader:="F/I"   ' 6
        .AddCol sheader:="Cash"   ' 7
        .AddCol sheader:="Type"   ' 8
        .AddCol sheader:="Disc/Non-Disc"   ' 9
        .AddCol sheader:="Trade Restrictions"   ' 10
        .AddCol sheader:="Custodian No"   ' 11
        .AddCol sheader:="Custodian Name"   ' 12
        .AddCol sheader:="Broker Code"   ' 13
        .AddCol sheader:="Broker Name"     ' 14 
        .AddCol sheader:="Total Mkt Value"   ' 15
        .AddCol sheader:="Comm Rate"   ' 16
        .AddCol sheader:="Dis Pct"   ' 17
        .AddCol sheader:="U ST-G/L"   ' 18
        .AddCol sheader:="U LT-G/L"   ' 19
      
        .EndUpdate
        
    End With
    '
    ' Restore the column layout
    frmPortfolioDiversification.iGridComposite.LayoutCol = GetSetting("Demo_Restore_layout", "LayoutStrings", "Col")
    Call Log("Opening form" & frmPortfolioDiversification.iGridComposite.LayoutCol)
Here's what I get in the log file:

引用:

10:15:45 PM: Opening form
1|Width|90|1|Order|1|1|Visible|1|2|Width|150|2|Order|2|2|Visible|1|3|Width|61|3|Order|3|3|Visible|1|4|Width|180|4|Order|4|4|Visible|1|
5|Width|42|5|Order|5|5|Visible|0|6|Width|24|6|Order|6|6|Visible|0|7|Width|69|7|Order|7|7|Visible|1|8|Width|65|8|Order|10|8|Visible|1|
9|Width|61|9|Order|11|9|Visible|1|10|Width|46|10|Order|12|10|Visible|1|11|Width|38|11|Order|13|11|Visible|1|12|Width|51|12|Order|14|12|Visible|1|
13|Width|69|13|Order|15|13|Visible|1|14|Width|61|14|Order|16|14|Visible|1|15|Width|46|15|Order|17|15|Visible|1|16|Width|71|16|Order|18|16|Visible|0|
17|Width|48|17|Order|19|17|Visible|0|18|Width|62|18|Order|8|18|Visible|0|19|Width|61|19|Order|9|19|Visible|0|


Note that several columns are Visible|0| - 5, 6, 16, 17, 18, and 19.

I can confirm that the Visible|0| columns are in fact hidden as soon as the form and grid appear, and I haven't added any rows. I don't understand why the string I saved and the string I get back do not match.

Once I load the grid, the hidden columns become visible (I do not make them visible in the code where I load the grid, they just reappear). But if I try to move a column, then close the form and reopen it, I get the same results as above and the column I moved (once the grid loads) is back where it started.

Not sure what I'm doing wrong.

Thanks.

Troy
Igor/10Tec
2018-11-21T08:55:58Z
We could not reproduce the issue based on your code. Send us, please, a project that demonstrates the issue.
Troy
  • Troy
  • Newbie Topic Starter
2018-11-21T15:30:39Z
Igor

In my attempt to strip out 98% of my code that you wouldn't need to see to troubleshoot this, I discovered this: it appears to be caused by changing the width of a grid. Here are my steps:

I call for the form to load and I immediately build the grid in the default order (as the columns are created) - see my previous post
I skip the call to get the saved column order to prove that the grid will display in the order I created them - and it does.
I move a bunch of columns around.
I close the form, saving the column order
I reload the form again and build the grid again
This time I do allow the grid to use the last saved setting - and it works just fine
I can move column all over the place, exit, reopen, and all is well.

But...

If between the time I open the form (with the grid in whatever order it's in - default or rearranged ) and the time I close the form (and save the new column settings) if I change the width of the grid, it messes up the column order the next time I open the form and put the grid in the saved order.

I allow the users to resize the form using spinners. When they change the width of the form, I adapt the width of the grids so that they always fill as much space as possible. Here's my code:

Public Sub SetGridWidth(iPDFormWidth As Integer)

    '**************************************************************
    '
    ' Name: SetGridWidth
    ' Written by:  Troy Gagnon
    '
    ' Purpose: Dynamically sizes the widths of the grids on the 
    '          PD form to adapt to the size of the form itself.
    '
    ' Date          By          Description
    ' 02/01/2018    Troy Gagnon Original release for Version 5.0
    '
    '**************************************************************
    
    Dim iGridWidth As Integer
    
    With frmPortfolioDiversification
        '
        ' iPDFormWidth is a global variable for the size of the form the user has selected when they resize the form    
        .Width = iPDFormWidth
        '
        ' Calculate the grid width based on the form width (make it 18 pixels smaller so it fits with a border remaining)
        ' I use the iGridAssetClassification.left value as a starting point.  All the grids on this form start at the same
        ' .left position so as long as I pick one, I have a good reference point to do the calculation.
        iGridWidth = iPDFormWidth - .iGridAssetClassification.Left - 18
        '
        ' Set each grid on the form to the new width        
        .iGridAssetClassification.Width = iGridWidth
        .iGridComposite.Width = iGridWidth
        .iGridSectors.Width = iGridWidth
        .iGridCap.Width = iGridWidth
        .iGridTradeModel.Width = iGridWidth
        .iGridBlock.Width = iGridWidth
        .iGridBondMaturity.Width = iGridWidth
        .btnMinimize.Left = iPDFormWidth - 40   ' re-position one button so it's not cut off if the form gets narrower       
       
    End With

End Sub
If I comment out the call to this one routine, the grid columns all work as expected. So, I suspect that changing the width of the grid does something to the column order.

Thanks for taking a look at this.

Troy
Igor/10Tec
2018-11-21T16:44:28Z
I am ready to do my best to fix the problem, but I need a sample I can use to reproduce the problem in 100% cases. Can you automate the steps leading to the problem?
Troy
  • Troy
  • Newbie Topic Starter
2018-11-21T16:47:14Z
Igor

I will put something together and send it along. Give me 24 hours and I'll see what I can put together.

Again, thank you.

Troy