locked activesheet

Posted by: lg_sony_27 on 8 September 2017, 2:36 pm EST

  • Posted 8 September 2017, 2:36 pm EST

    Hi!


    I want the activesheet to be locked whenever I click my lock button...and my code below works but with a little problem...


    I click the lock button and the activesheet is locked, but when i closed the program and reopen it and then i press the delete key i can still delete the record from the activesheet...but if i press any other key except the delete key i cannot type anything on the sheet (which is what i want) after doing so, that's the only time my activesheet will be locked from deletion, it seems that a key must be pressed first before locking will take place.


    Thank you!<FONT size=2>


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Private</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub</FONT></FONT><FONT size=2> btnLockUnlock_Click_1(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> sender </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.Object, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>ByVal</FONT></FONT><FONT size=2> e </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> System.EventArgs) </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Handles</FONT></FONT><FONT size=2> btnLockUnlock.Click


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Dim</FONT></FONT><FONT size=2> IsLocked </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Boolean</FONT></FONT><FONT size=2> = FpSpread1.ActiveSheet.DefaultStyle.Locked


    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''Dim imageIcon As String = IIf(IsLocked, "lock_icon.gif", "lock_icon_open.gif")

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If</FONT></FONT><FONT size=2> cnn.State = ConnectionState.Closed </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then</FONT></FONT><FONT size=2> cnn.Open()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If</FONT></FONT><FONT size=2> gstrUserlevel = </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"System Administrator"</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If</FONT></FONT><FONT size=2> IsLocked = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Then

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.FpSpread1.ActiveSheet.DefaultStyle.Locked = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>False

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

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''Using cnn As New SqlConnection(My.Settings.ConnectionString)

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

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''cnn.Open()

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Try

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Using</FONT></FONT><FONT size=2> cmdLockUnLock </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> SqlCommand(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"UPDATE tblLockUnlock SET Locked=@Bol "</FONT></FONT><FONT size=2> & _


    </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"WHERE Sheets=@Sheets "</FONT></FONT><FONT size=2> & _


    </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"AND Dept=@Dept"</FONT></FONT><FONT size=2>, cnn)


    cmdLockUnLock.Parameters.AddWithValue(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"@Bol"</FONT></FONT><FONT size=2>, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"False"</FONT></FONT><FONT size=2>)


    cmdLockUnLock.Parameters.AddWithValue(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"@Sheets"</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.FpSpread1.ActiveSheetIndex)


    cmdLockUnLock.Parameters.AddWithValue(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"@Dept"</FONT></FONT><FONT size=2>, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"HS"</FONT></FONT><FONT size=2>)


    cmdLockUnLock.ExecuteNonQuery()


    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''cnn.Close()

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Using

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Catch</FONT></FONT><FONT size=2> ex </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> SqlException


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>For</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Each</FONT></FONT><FONT size=2> er </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> SqlError </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>In</FONT></FONT><FONT size=2> ex.Errors


    MessageBox.Show(er.Message)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Next

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Try

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

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''End Using

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Else

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.FpSpread1.ActiveSheet.DefaultStyle.Locked = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>True

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

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''Using cnn As New SqlConnection(My.Settings.ConnectionString)

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

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''cnn.Open()

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Try

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Using</FONT></FONT><FONT size=2> cmdLockUnLock </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>New</FONT></FONT><FONT size=2> SqlCommand(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"UPDATE tblLockUnlock SET Locked=@Bol "</FONT></FONT><FONT size=2> & _


    </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"WHERE Sheets=@Sheets "</FONT></FONT><FONT size=2> & _


    </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"AND Dept=@Dept"</FONT></FONT><FONT size=2>, cnn)


    cmdLockUnLock.Parameters.AddWithValue(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"@Bol"</FONT></FONT><FONT size=2>, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"True"</FONT></FONT><FONT size=2>)


    cmdLockUnLock.Parameters.AddWithValue(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"@Sheets"</FONT></FONT><FONT size=2>, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Me</FONT></FONT><FONT size=2>.FpSpread1.ActiveSheetIndex)


    cmdLockUnLock.Parameters.AddWithValue(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"@Dept"</FONT></FONT><FONT size=2>, </FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"HS"</FONT></FONT><FONT size=2>)


    cmdLockUnLock.ExecuteNonQuery()


    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''cnn.Close()

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Using

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Catch</FONT></FONT><FONT size=2> ex </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> SqlException


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>For</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Each</FONT></FONT><FONT size=2> er </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>As</FONT></FONT><FONT size=2> SqlError </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>In</FONT></FONT><FONT size=2> ex.Errors


    MessageBox.Show(er.Message)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Next

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Try

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

    </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>''End Using

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Else

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

    MessageBox.Show(</FONT><FONT color=#800000 size=2><FONT color=#800000 size=2>"Your access level prevents you from clicking this button."</FONT></FONT><FONT size=2>, ProgName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>If

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

    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Call</FONT></FONT><FONT size=2> LockUnlockImage()


    </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>End</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>Sub

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

    Hello,

    I am not able to replicate this issue at my end. I have attached  a sample application which is working fine , please have a look at the attached sample and make the necessary changes to the project so that I can replicate the issue at my end . If I set the active sheet's default style to locked the delete key doesn't work too.

    I am using Spread 5 latest build.

    Thanks,

     


    2011/04/DeleteKeyFunctionality-2.zip
  • Replied 8 September 2017, 2:36 pm EST

    thanks DeepakSharma for your sample code. I relocate the input map code in my display button and that solved this issue as well as the other issue i posted here.


    Thanks!

Need extra support?

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

Learn More

Forum Channels