In the documentation for the TreeView, it shows how to add a node to the tree via code with a local datasource; however, there is no example of how to add a node when using a remote SQL datasource. Can you help me out with these two questions:
1. Do we need to add a record manually to the treeview or will the treeview auto-detect the new record in the updated datasource?
2. I am not able to get RefreshNode(), to work correctly. I am able to get Refresh to work though. How can we get the parent node refreshed with the new child without doing a full refresh?
3. Once we add the new node, how do we get the treeview to select that newly added node?
Here is my code so far, thanks again for all the awesome products!
async Task AddRecord()
{
// This is the record in the database
OrgUnit orgUnit = new OrgUnit
{
// OrgId is the ID and will be auto-set by the database
ParentOrgId = selectedNode.OrgId,
Name = "New unit " + this.index
};
OrgUnit saved = await dal.SaveOrgUnitAsync(orgUnit);
// This is the data item stored in the TreeView component node
var orgUnitPickerItem = new OrgUnitPickerItem
{
OrgId = saved.OrgId,
ParentOrgId = saved.ParentOrgId,
Name = saved.Name,
HasChild = false,
Expanded = false
};
// This is the data source used by the TreeView
PickList.Add(orgUnitPickerItem);
//List<OrgUnitPickerItem> TreeData = new List<OrgUnitPickerItem>();
//TreeData.Add(orgUnitPickerItem);
//await this.tree.AddNodes(TreeData, this.selectedNodeId, null, false);
//string NodeId = "tree_" + this.index.ToString();
//await this.tree.BeginEdit(NodeId);
this.index = this.index + 1;
await this.tree.AddNodes(orgUnitPickerItem, selectedNode);
//this.tree.Refresh();
// this.selectedNode is type OrgUnitPickerItem and is the parent
await this.tree.RefreshNode(this.selectedNode, orgUnitPickerItem);
}