Back to Devexpress

How to: Protect a Chart

windowsforms-17532-controls-and-libraries-spreadsheet-examples-charts-how-to-protect-a-chart.md

latest2.4 KB
Original Source

How to: Protect a Chart

  • Feb 26, 2026
  • 2 minutes to read

After you create a chart, you can apply chart protection to prevent your chart from being modified by a user. To protect a chart, utilize the ChartOptions.Protectionproperty. After chart protection is specified, the chart becomes completely locked, so that an end-user cannot select the chart, modify its elements or change chart data references.

You can also protect the entire worksheet where the chart is located by using the Worksheet.Protect method. For detailed information on the protection functionality in the SpreadsheetControl, refer to the Protection article.

The following example demonstrates how to create a clustered column chart and apply chart protection using the ChartOptions.Protection property.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["chartTask3"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:D4"]);
chart.TopLeftCell = worksheet.Cells["H2"];
chart.BottomRightCell = worksheet.Cells["N14"];

// Specify the chart style.
chart.Style = ChartStyle.ColorDark;

// Apply the chart protection.
chart.Options.Protection = ChartProtection.All;
vb
Dim worksheet As Worksheet = workbook.Worksheets("chartTask3")
workbook.Worksheets.ActiveWorksheet = worksheet

' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:D4"))
chart.TopLeftCell = worksheet.Cells("H2")
chart.BottomRightCell = worksheet.Cells("N14")

' Specify the chart style.
chart.Style = ChartStyle.ColorDark

' Apply the chart protection.
chart.Options.Protection = ChartProtection.All

See Also

How to: Create and Modify a Chart