Skip to main content
Row

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ProtectedRange Interface

An association of a worksheet range and credentials required to unlock it for editing.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v24.2.Core.dll

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

public interface ProtectedRange

#Remarks

A simple scenario that uses the ProtectedRange is illustrated in the code snippet below.

The entire worksheet is protected with a “password” password. End-users can only select cells.

On an attempt to edit range “C3:E8” on a protected sheet, the end-user will be prompted for a password (“123”) unless the application which loaded the worksheet is not run under the same account as the application which has executed the following code snippet. If it is so, a password is not required to edit the range “C3:E8”.

View Example

workbook.BeginUpdate()
Dim worksheet As Worksheet = workbook.Worksheets(0)
worksheet("C3:E8").Borders.SetAllBorders(Color.Black, BorderLineStyle.Thin)

' Give specific user permission to edit a range in a protected worksheet. 
Dim protectedRange As ProtectedRange = worksheet.ProtectedRanges.Add("My Range", worksheet("C3:E8"))
Dim permission As New EditRangePermission()
permission.UserName = Environment.UserName
permission.DomainName = Environment.UserDomainName
permission.Deny = False
protectedRange.SecurityDescriptor = protectedRange.CreateSecurityDescriptor(New EditRangePermission() { permission })
protectedRange.SetPassword("123")

' Protect a worksheet.
If Not worksheet.IsProtected Then
    worksheet.Protect("password", WorksheetProtectionPermissions.Default)
End If

worksheet.ActiveView.ShowGridlines = False
workbook.EndUpdate()
See Also