Skip to main content

VGridControlBase.CustomizationFormCreatingCategory Event

Fires when a new category is about to be created in Customization Form.

Namespace: DevExpress.XtraVerticalGrid

Assembly: DevExpress.XtraVerticalGrid.v24.2.dll

Declaration

public event CustomizationFormCreatingCategoryEventHandler CustomizationFormCreatingCategory

Event Data

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

Property Description
CanCreate Gets or sets a value specifying whether the creation of a new category row with the specified caption is allowed within the Customization Form.
Category Gets the processed category row. Inherited from CategoryEventArgs.

Remarks

To create a new category in Customization Form, switch to the Categories page, click New… and enter the category’s caption. Users can drag the new category to the grid and then drag rows to the category.

The CustomizationFormCreatingCategory event fires after the user clicks Ok and before the new category is added to the grid’s Rows collection.

The Category event parameter returns the category that is about to be created. Set the CanCreate parameter to false to discard the new category.

Example

When users create a new category, they enter the category caption. The example below shows how to check whether a category with the same caption already exists in the grid. If the captions match, the code shows a warning message.

image

The code enumerates grid categories to compare their captions with the new category caption. Refer to the following help topic for more information on how to enumerate grid rows: Tree Traversal.

using DevExpress.XtraVerticalGrid.Events;

public class RowOperationCategoryCaption : RowOperation {
    private string newCategoryCaption;
    private bool found = false;
    public RowOperationCategoryCaption(string newCaption) {
        this.newCategoryCaption = newCaption;
    }
    public bool Found {
        get { return found; }
    }
    public override void Execute(BaseRow row) {
        // Check if the processed row is a category.
        if (row.XtraRowTypeID != 0) return;
        // Compare the row caption with the entered caption.
        if (row.Properties.Caption == newCategoryCaption) found = true;
    }
   public override bool CanContinueIteration(BaseRow row){
      return !Found;
   }
}

private void vGridControl1_CustomizationFormCreatingCategory(object sender, 
CustomizationFormCreatingCategoryEventArgs e) {
    RowOperationCategoryCaption operation = new RowOperationCategoryCaption(e.Category.Properties.Caption);
    VGridControl vGridControl = sender as VGridControl;
    // Perform the operation.
    vGridControl.RowsIterator.DoOperation(operation);
    // Display a warning message if the match is found.
    if (operation.Found) {
        string messageText = 
            "A category row with the same caption already exists.\r\n" + 
            "Click Yes to modify the new category row caption.\r\n" +
            "Click No to create a new category row with the specified caption.\r\n"+
            "Do you want to enter new caption?";
        DialogResult result = MessageBox.Show(messageText,"Match found",
          MessageBoxButtons.YesNo);
        // Prohibit to create a new row depending on the user choice.
        if (result == DialogResult.Yes) e.CanCreate = false;
    }
}
See Also