private static void onCreateLayer(Object sender, ClickEventArgs e, Boolean addSelection) { NlmTreeListView listView = e.ListView; listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.UnregisterNotification(); IILayer layer = MaxLayers.CreateLayer(true, addSelection); UIntPtr handle = MaxAnimatable.GetHandleByAnim(layer); LayerTreeNode layerTreeNode = new LayerTreeNode(handle, listView.NodeControl.HandleMap); // Get parent node. BaseTreeNode parentTreeNode = null; if (listView.SelectedObjects.Count > 0) { BaseTreeNode treeNode = listView.SelectedObjects[0] as BaseTreeNode; if (treeNode is FolderTreeNode) { parentTreeNode = treeNode; } if (treeNode is LayerTreeNode) { parentTreeNode = treeNode.Parent; } } // Add folder to listview, ensure is visible by expanding parents. listView.AddObject(layerTreeNode, parentTreeNode); if (parentTreeNode != null) { listView.Expand(parentTreeNode); } // Scroll to new item. Int32 parentIndex = listView.IndexOf(layerTreeNode); if (parentIndex != -1) { listView.EnsureVisible(parentIndex); } // Sort, select listView.Sort(listView.NlmColumns.NameColumn, SortOrder.Ascending); listView.SelectedObjects = new List <Object> { layerTreeNode }; // Focus on the listview to ensure text entry goes to the edit box, and begin edit. listView.Focus(); listView.EditModel(layerTreeNode); // Register notification. listView.NodeControl.MaxEvents.LayerEvents.LayerCreated.RegisterNotification(); }