Freezing Columns in 3 level Heirarchy

Posted by: himaheshh on 8 September 2017, 2:26 pm EST

  • Posted 8 September 2017, 2:26 pm EST

    <FONT size=2>

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (fpSpreadRangeDecision.ActiveSheet != </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>null</FONT></FONT><FONT size=2>)


    {


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (!m_blnFreezeAppliied) </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//Freeze

    </FONT></FONT><FONT size=2>

    {


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (fpSpreadRangeDecision.ActiveSheet.SelectionCount == 0)


    {


    </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>MessageBox</FONT></FONT><FONT size=2>.Show(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Atleast one column should be selected in Parent in order to freeze"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Information"</FONT></FONT><FONT size=2>, </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>MessageBoxButtons</FONT></FONT><FONT size=2>.OK, </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>MessageBoxIcon</FONT></FONT><FONT size=2>.Information);


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2>;


    }


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> intColumnIndex = fpSpreadRangeDecision.ActiveSheet.ActiveCell.Column.Index + 1;


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (intColumnIndex > 4)


    {


    tsmFreezeColumn.Text = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"Un&Freeze columns"</FONT></FONT><FONT size=2>;


    fpSpreadRangeDecision.ActiveSheet.FrozenColumnCount = intColumnIndex;


    </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ArrayList</FONT></FONT><FONT size=2> alChildSht = fpSpreadRangeDecision.ActiveSheet.GetChildSheets();


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>foreach</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>SheetView</FONT></FONT><FONT size=2> shtvwChild </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>in</FONT></FONT><FONT size=2> alChildSht)


    {


    shtvwChild.FrozenColumnCount = intColumnIndex;


    </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ArrayList</FONT></FONT><FONT size=2> alGrandChildSht = shtvwChild.GetChildSheets();


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>foreach</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>SheetView</FONT></FONT><FONT size=2> shtvwGrandChild </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>in</FONT></FONT><FONT size=2> alGrandChildSht)


    {


    shtvwGrandChild.FrozenColumnCount = intColumnIndex;


    }


    }


    m_blnFreezeAppliied = !m_blnFreezeAppliied;


    m_intColFreezeCount = fpSpreadRangeDecision.ActiveSheet.FrozenColumnCount;


    }


     


    }


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</FONT></FONT><FONT size=2> </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// Un freeze option...

    </FONT></FONT><FONT size=2>

    {


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (fpSpreadRangeDecision.ActiveSheet.ActiveCell != </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>null</FONT></FONT><FONT size=2>)


    {


    tsmFreezeColumn.Text = </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"&Freeze from selected column"</FONT></FONT><FONT size=2>;


    m_intColFreezeCount = 4;


    fpSpreadRangeDecision.ActiveSheet.FrozenColumnCount = m_intColFreezeCount;


    </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ArrayList</FONT></FONT><FONT size=2> alChildSht = fpSpreadRangeDecision.ActiveSheet.GetChildSheets();


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>foreach</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>SheetView</FONT></FONT><FONT size=2> shtvwChild </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>in</FONT></FONT><FONT size=2> alChildSht)


    {


    shtvwChild.FrozenColumnCount = m_intColFreezeCount;


    </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ArrayList</FONT></FONT><FONT size=2> alGrandChildSht = shtvwChild.GetChildSheets();


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>foreach</FONT></FONT><FONT size=2> (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>SheetView</FONT></FONT><FONT size=2> shtvwGrandChild </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>in</FONT></FONT><FONT size=2> alGrandChildSht)


    {


    shtvwGrandChild.FrozenColumnCount = m_intColFreezeCount;


    }


    }


    }


     


    m_blnFreezeAppliied = !m_blnFreezeAppliied;


    }


    Using the above code, we are trying to enable the freezing of columns in a 3 level heirarchial view. Our requirement is to freeze the first 4 columns by default.  If the user wish to change, the user will select the column and apply the freezing. But that works only if the user selects  a column in the Parent level. If the User selects a column in  any of the Child , the code fpSpreadRangeDecision.ActiveSheet.ActiveCell.Column.Index  always returns a 0.


    Any help to get the selected column in the Child rows will be greatly appreciated.


    Thanks


    Mahesh

    </FONT>
  • Replied 8 September 2017, 2:26 pm EST

    Mahesh,

    In order to <font size="2">get the selected column index in the Child rows y</font>ou first need to query whether the parent view's cell has been clicked or the child view's cell in the CellClick event having e.View parameter passed in. It's
    the SpreadView object that contains the cell you clicked. You can then check it's Parent property. If the Parent
    property returns another SpreadView object, then the cell clicked on is a
    child SpreadView object; otherwise it is the parent.

    Hope this will help you. Thanks.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels