All docs
V20.1
20.2 (EAP/Beta)
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

MVCxDiagramItemUpdateValues<TItem, TKey>.MapInsertedItemKey(TItem, TKey) Method

Specifies the key value of the inserted item.

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v20.1.dll

Declaration

public void MapInsertedItemKey(
    TItem item,
    TKey itemKey
)
Public Sub MapInsertedItemKey(
    item As TItem,
    itemKey As TKey
)

Parameters

Name Type Description
item TItem

The inserted item.

itemKey TKey

The inserted item's key.

Remarks

The Diagram extension builds a diagram based on the nodes' and edges' key values.

The extension retrieves keys for all bound items (nodes and edges) from a data source. If a new item is created by a user, you should obtain the item's key and send it to the extension. The key can be autogenerated by a data source on item inserting, or created manually in code. Call the MapInsertedItemKey method for each created/inserted data item to map keys to items.

The GetBatchUpdateResult method combines all mapped keys and returns them as an action result to the client instance of the Diagram extension.

NOTE

If an item's key is not determined, the "The inserted item key is undefined. Use the MVCxDiagramItemUpdateValues.MapInsertedItemKey method to specify the key value for a newly inserted {2}." exception is thrown.

@Html.DevExpress().Diagram(settings => {
    settings.Name = "Diagram";

    settings.BatchUpdateRouteValues = new { Controller = "DataBinding", Action = "LinearUpdate" };

    settings.Mappings.Node.Key = "ID";
    settings.Mappings.Node.ParentKey = "ParentID";
    settings.Mappings.Node.Text = "DepartmentName";

    settings.SettingsAutoLayout.Type = DevExpress.Web.ASPxDiagram.DiagramAutoLayout.Tree;

}).Bind(Model).GetHtml()
public ActionResult LinearUpdate(MVCxDiagramNodeUpdateValues<EditableDepartment, int> nodeUpdateValues) {
    foreach(var item in nodeUpdateValues.Update)
        DepartmentProvider.Update(item);
    foreach(var itemKey in nodeUpdateValues.DeleteKeys)
        DepartmentProvider.Delete(itemKey);
    foreach(var item in nodeUpdateValues.Insert) {
        var insertedItem = DepartmentProvider.Insert(item);
        nodeUpdateValues.MapInsertedItemKey(item, insertedItem.ID);
    }
    return DiagramExtension.GetBatchUpdateResult(nodeUpdateValues);
}

Online Demo

Diagram - Tree from Linear Data Structure

See Also