Skip to main content

SpreadsheetControl.DefinedNameConflictResolving Event

Occurs when a formula or sheet being moved or copied contains a defined name that already exists in the destination worksheet or workbook.

Namespace: DevExpress.XtraSpreadsheet

Assembly: DevExpress.XtraSpreadsheet.v24.1.dll

NuGet Package: DevExpress.Win.Spreadsheet

Declaration

public event DefinedNameConflictResolvingEventHandler DefinedNameConflictResolving

Event Data

The DefinedNameConflictResolving event's data class is DefinedNameConflictResolvingEventArgs. The following properties provide information specific to this event:

Property Description
Cancel Gets or sets a value indicating whether the event should be canceled. Inherited from CancelEventArgs.
NameStatus Gets the status of the conflict name.
NewName Gets or sets the name for a new version of the defined name being moved or copied.
OldName Gets the defined name for which the event is fired.
UsedNames Provides access to the set of table and defined names existing in the destination workbook.
UseExistingName Gets or sets a value indicating whether to use the defined name specified on the destination worksheet or workbook in the conflict situation.
Validator Gets or sets a validator used to check whether a new version of the conflict name is valid and unique.

Remarks

Use the DefinedNameConflictResolving event to handle a name conflict error, which occurs when a copied name already exists in the destination worksheet or workbook.

Spreadsheet_NameConflictDialog

The following example demonstrates how to handle the DefinedNameConflictResolving event to always use the defined name specified in the destination worksheet or workbook when names conflict, and suppress displaying the Name Conflict dialog. To do this, set the DefinedNameConflictResolvingEventArgs.UseExistingName and Handled parameters to true.

spreadsheet.DefinedNameConflictResolving += spreadsheet_DefinedNameConflictResolving;
// ...

private void spreadsheet_DefinedNameConflictResolving(object sender, DefinedNameConflictResolvingEventArgs e)
{
    e.UseExistingName = true;
    e.Handled = true;
}

To create a new version of the defined name being copied, assign the required name to the NewName parameter. The default parameter value is an automatically generated defined name you can use or modify.

The DefinedNameConflictResolvingEventArgs.Validator parameter provides access to the default validator that enables you to validate a new version of the conflicting defined name before pasting it into the destination worksheet/workbook. To specify a custom validator, create an object that implements the IDefinedNameValidator interface and assign it to the DefinedNameConflictResolvingEventArgs.Validator property.

See Also