A bug? ResetLocked does not work as expected

Posted by: bdota on 8 September 2017, 2:22 pm EST

  • Posted 8 September 2017, 2:22 pm EST

    Greetings,

    this code:

                 fpSpread1.ActiveSheet.LockBackColor = Color.Red;

                fpSpread1.ActiveSheet.Rows[2].Locked = true;

                fpSpread1.ActiveSheet.Cells[2, 3].Locked = false;

                fpSpread1.ActiveSheet.Cells[2, 3].ResetLocked();

     

    ok, so far so good ... the cell is also locked, BUT when I run this

    MessageBox.Show(fpSpread1.ActiveSheet.Cells[2, 3].Locked.ToString());

     it is still returning FALSE. which is wrong.

    so what am I doing wrong in here? I expect the message box to show True not False. 

  • Replied 8 September 2017, 2:22 pm EST

    Hello,


    MessageBox is giving you the correct answer which is False because ResetLocked() when called on a cell's object resets the locked state for the cell and makes the cell inherit the locked state from the default cell ( which is by default set to false) and not from the default row.


    Thanks.

  • Replied 8 September 2017, 2:22 pm EST

    Thanks,

    but that cell is now really locked. I cannot type in it.  but why the Locked is returning False :(

     


     
      

     

  • Replied 8 September 2017, 2:22 pm EST

    Hello,

    This is because the Lock information it is now returning is for the Cell , which has actually Locked set to false.The locked state of cell is the result of the Locked Row not for cell.

    Initially when the page loads Cells lock state is set to False you are again setting the lock information to False which actually has no effect of the Cell's lock state and the message box always return the false.

    In order to reset the locked state for Cell you need to first set the Locked property to True for the cell and then resetting the Locked state will return false.

    e.g.

                fpSpread1.ActiveSheet.LockBackColor = Color.Red;
                fpSpread1.ActiveSheet.Rows[2].Locked = true;
                fpSpread1.ActiveSheet.Cells[2, 3].Locked = true;
                fpSpread1.ActiveSheet.Cells[2, 3].ResetLocked();

    now  MessageBox.Show(fpSpread1.ActiveSheet.Cells[2, 3].Locked.ToString()); will return "False" which is correct.

    I hope it clears the doubt.

     

    Thanks,

Need extra support?

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

Learn More

Forum Channels