Skip to main content
A newer version of this page is available. .

CustomizationFormCreatingCategoryEventArgs.CanCreate Property

Gets or sets a value specifying whether the creation of a new category row with the specified caption is allowed within the Customization Form.

Namespace: DevExpress.XtraVerticalGrid.Events

Assembly: DevExpress.XtraVerticalGrid.v18.2.dll

Declaration

public bool CanCreate { get; set; }

Property Value

Type Description
Boolean

true if the category row being created can be added to the VGridControlBase.Rows collection; otherwise false.

Remarks

Creating a new category row within the Customization Form is a two-step process. The first step is user-dependent, it implies that the user is attempting to create a new category row by performing the following actions:

  • Clicking the New… button within the Categories tabbed page of the Customization Form, as a result the New Category dialog window is invoked;
  • Entering a caption for the category row being created and clicking the OK button.

Upon completion of the first step, a stand-alone instance of the CategoryRow object is created and its RowProperties.Caption property is set to the value entered. The created category row instance is not added to any grid’s row collection.

The second step is performed if a handler is assigned to the VGridControlBase.CustomizationFormCreatingCategory event. This event allows you to cancel adding a new category row to the VGridControlBase.Rows collection. For instance, you could prohibit category row addition if a row with the same caption already exists. For this purpose, set the CanCreate event parameter to false. The newly created row can be accessed by the CategoryEventArgs.Category property.

If the CanCreate property value is left set to true (the default value) in a handler, the header of the newly created category row becomes displayed on the Categories page of the Customization Form. This means that a row has been successfully added to the VGridControlBase.Rows collection of top-level grid rows, but is hidden - its BaseRow.Visible property is false and BaseRow.VisibleIndex is -1. The row header can then be dragged from the Customization Form onto the header panel to make the row visible within the grid control.

If the event handler sets the CanCreate parameter to false, the row adding dialog is displayed again. It allows users to correct the row caption or to cancel adding the row by clicking the Cancel button.

Example

This example responds to a user’s attempt to create a new category row. After clicking the New… button within the Categories page of the Customization Form, an end-user enters the caption for the category row being created. The sample code demonstrates how to handle the CustomizationFormCreatingCategory event in order to search for an existing category row with the same caption and if found, asks the user what they want to do.

While searching, the code visits all the grid rows with the help of the VGridRowsIterator object and performs a specific caption comparison operation on each of them. The operation to be performed on visited rows is a descendant of the RowOperation class. The operation class constructor accepts a parameter representing the newly entered category row’s caption which to compare against the RowProperties.Caption property of rows. The Found property implemented in the operation class is used to recognize whether the match was found.

The picture below displays how the code reacts to entering an already existing caption for the new category row being created.

VGridControl_CustomizationFormCreatingCategory_example

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) {
        // checking if the processed row type is category
        if (row.XtraRowTypeID != 0) return;
        // comparing the processed row caption with the entered one
        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);
    // performing the declared comparison operation
    vGridControl1.RowsIterator.DoOperation(operation);
    // if the match is found, displaying a warning message
    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);
        // prohibiting new row creation depending upon the user choice
        if (result == DialogResult.Yes) e.CanCreate = false;
    }
}
See Also