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!


    Private Sub btnLockUnlock_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLockUnlock.Click


    Dim IsLocked As Boolean = FpSpread1.ActiveSheet.DefaultStyle.Locked


    ''Dim imageIcon As String = IIf(IsLocked, "lock_icon.gif", "lock_icon_open.gif")


    If cnn.State = ConnectionState.Closed Then cnn.Open()


    If gstrUserlevel = "System Administrator" Then


    If IsLocked = True Then


    Me.FpSpread1.ActiveSheet.DefaultStyle.Locked = False


    ''Using cnn As New SqlConnection(My.Settings.ConnectionString)


    ''cnn.Open()


    Try


    Using cmdLockUnLock As New SqlCommand("UPDATE tblLockUnlock SET Locked=@Bol " & _


    "WHERE Sheets=@Sheets " & _


    "AND Dept=@Dept", cnn)


    cmdLockUnLock.Parameters.AddWithValue("@Bol", "False")


    cmdLockUnLock.Parameters.AddWithValue("@Sheets", Me.FpSpread1.ActiveSheetIndex)


    cmdLockUnLock.Parameters.AddWithValue("@Dept", "HS")


    cmdLockUnLock.ExecuteNonQuery()


    ''cnn.Close()


    End Using


    Catch ex As SqlException


    For Each er As SqlError In ex.Errors


    MessageBox.Show(er.Message)


    Next


    End Try


    ''End Using


    Else


    Me.FpSpread1.ActiveSheet.DefaultStyle.Locked = True


    ''Using cnn As New SqlConnection(My.Settings.ConnectionString)


    ''cnn.Open()


    Try


    Using cmdLockUnLock As New SqlCommand("UPDATE tblLockUnlock SET Locked=@Bol " & _


    "WHERE Sheets=@Sheets " & _


    "AND Dept=@Dept", cnn)


    cmdLockUnLock.Parameters.AddWithValue("@Bol", "True")


    cmdLockUnLock.Parameters.AddWithValue("@Sheets", Me.FpSpread1.ActiveSheetIndex)


    cmdLockUnLock.Parameters.AddWithValue("@Dept", "HS")


    cmdLockUnLock.ExecuteNonQuery()


    ''cnn.Close()


    End Using


    Catch ex As SqlException


    For Each er As SqlError In ex.Errors


    MessageBox.Show(er.Message)


    Next


    End Try


    ''End Using


    End If


    Else


    MessageBox.Show("Your access level prevents you from clicking this button.", ProgName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


    End If


    Call LockUnlockImage()


    End Sub

  • 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