Hi,
I have configured my tree list as follows;
_oTreeList.DataCacheMode = TreeListDataCacheMode.Disabled;
_oTreeList.Settings.GridLines = GridLines.Both;
_oTreeList.Settings.ShowRoot = true;
_oTreeList.Settings.ShowTreeLines = false;
_oTreeList.SettingsBehavior.AllowFocusedNode = false;
_oTreeList.SettingsBehavior.AllowDragDrop = false;
_oTreeList.SettingsEditing.AllowNodeDragDrop = false;
_oTreeList.SettingsSelection.Enabled = true;
_oTreeList.NodeExpanding += new TreeListNodeCancelEventHandler(NodeExpanding);
_oTreeList.CustomJSProperties += new TreeListCustomJSPropertiesEventHandler(CustomJSProperties);
_oTreeList.ClientSideEvents.NodeClick = "NodeClick";
Javascript:
function NodeClick(s, e) {
CloseImportOptionsMenu();
bScroll = true;
var srcEl = null;
var bIsShift = false;
var bIsCtrl = false;
var sNodeKey = typeof (e.nodeKey) == "undefined" ? s.GetFocusedNodeKey() : e.nodeKey;
if (typeof(e.htmlEvent) != "undefined") {
srcEl = e.htmlEvent.srcElement ? e.htmlEvent.srcElement : e.htmlEvent.target;
bIsShift = e.htmlEvent.shiftKey;
bIsCtrl = e.htmlEvent.ctrlKey;
}
if (srcEl != null && srcEl.tagName == 'IMG') {
var Selected = isCtrl == false || s.IsNodeSelected(sNodeKey) == false;
s.SelectNode(sNodeKey, Selected);
SetImportNodeClass(s, sNodeKey);
e.cancel = true;
return;
}
if (bIsShift || bIsCtrl)
_aspxClearSelection();
if (bIsShift == false && bIsCtrl == false)
ClearTreeSelection(s);
if (bIsShift && s.cpLastSelected != null) {
var row1 = s.GetNodeHtmlElement(s.cpLastSelected);
var row2 = s.GetNodeHtmlElement(sNodeKey);
var index1 = row1.rowIndex;
var index2 = row2.rowIndex;
if (index1 > index2) {
var temp = index1;
index1 = index2;
index2 = temp;
}
var table = row1.parentNode.parentNode;
for (var n = index1; n <= index2; n++) {
var key = s.GetNodeKeyByRow(table.rows[n]);
if (key != null) {
s.SelectNode(key, true);
SetImportNodeClass(s, key);
}
}
}
else {
var Selected = bIsCtrl == false || s.IsNodeSelected(sNodeKey) == false;
s.SelectNode(sNodeKey, Selected);
SetImportNodeClass(s, sNodeKey);
}
LastSelectedNodeKey = sNodeKey;
}
When a user selects the node via the checkbox (SettingsSelection.Enabled = true) it doesn't trigger the NodeClcik event so I have added the following; _oTreeList.ClientSideEvents.SelectionChanged = "NodeClick"; but am unable to get the NodeKey of the focused node as I have disabled it.
How can I achieve this?
Cheers
Update: selecting the node via the checkbox does trigger the NodeClick event but I am unable to get the NodeKey using e.nodeKey, or s.GetFocusedNodeKey()
Update: I know I can use s.GetVisibleSelectedNodeKeys() but my aim is to get the last selected node key…
Sorry for spam posting…
Hello Jason,
Thank you for the detailed description of the issue. The current ASPxTreeList's implementation doesn't provide the functionality to obtain the key of a selected ASPxTreeList's node by handling the ASPxClientTreeList's SelectionChanged. We have the corresponding suggestion regarding this: Add new parameters to the client-side SelectionChanged event. Please track this suggestion to be notified when its status is changed.
As a possible solution, I suggest that you use the solution based on the How to use ASPxCheckBox in DataItemTemplate to emulate a selection and How to select a row in one click examples.
Regards,
Mike
Found a way of obtaining the last selected nodekey on the SelectionChanged Event;
function NodeSelect(s, e) {
var sNodeKeys = s.GetSelectionInput()['value'].split(' ');
var sNodeKey = sNodeKeys.length > 1 ? sNodeKeys[sNodeKeys.length - 1] : sNodeKeys[0];
treeLinking.cpLastSelected = sNodeKey;
}
Hello Jason,
We are glad to hear that you have found a solution. However, the GetSelectionInput method is private, so I can't guarantee that it'll work in all situations.
Thanks,
Mike