ASPxTreeList.GetSelectedNodes() Method
In This Article
Returns a list of selected nodes.
Namespace: DevExpress.Web.ASPxTreeList
Assembly: DevExpress.Web.ASPxTreeList.v24.2.dll
NuGet Package: DevExpress.Web
#Declaration
public List<TreeListNode> GetSelectedNodes()
#Returns
Type | Description |
---|---|
List<Tree |
The list of Tree |
#Remarks
A node is selected if its TreeListNode.Selected property is set to true
. End-users can select nodes via check boxes displayed within selection cells.
To learn more, see Selection.
Note
In virtual mode, the Get
The code sample below demonstrates tow to store the selection between requests.
html
<dx:ASPxTreeList ID="treeList" runat="server" ClientInstanceName="treeList" AutoGenerateColumns="False"
KeyFieldName="ItemId" ParentFieldName="ParentId" KeyboardSupport="True" OnDataBinding="atlSelection_DataBinding" OnCustomCallback="treeList_CustomCallback">
<Columns>
<dx:TreeListTextColumn FieldName="Code" />
<dx:TreeListTextColumn FieldName="Name" />
<dx:TreeListTextColumn FieldName="Description" />
<dx:TreeListTextColumn FieldName="ItemType" />
<dx:TreeListTextColumn FieldName="Price" >
<PropertiesTextEdit DisplayFormatString="{0:C}" />
</dx:TreeListTextColumn>
</Columns>
<SettingsPager PageSize="20" Mode="ShowPager" />
<SettingsBehavior AllowFocusedNode="true" AutoExpandAllNodes="True"
AllowSort="False" FocusNodeOnExpandButtonClick="true" />
<SettingsSelection Enabled="True" />
<SettingsEditing AllowNodeDragDrop="true" Mode="EditForm" />
</dx:ASPxTreeList>
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Save selection" AutoPostBack="false">
<ClientSideEvents Click="function (s, e) { treeList.PerformCallback('Save'); }" />
</dx:ASPxButton>
<dx:ASPxButton ID="ASPxButton2" runat="server" Text="Restore selection" AutoPostBack="false">
<ClientSideEvents Click="function (s, e) { treeList.PerformCallback('Restore'); }" />
</dx:ASPxButton>
private const string selectedNodesKey = "selectedNodesKey";
protected void treeList_CustomCallback(object sender, TreeListCustomCallbackEventArgs e) {
switch (e.Argument) {
case "Save":
SaveSelection();
break;
case "Restore":
RestoreSelection();
break;
}
}
private void SaveSelection() {
Session[selectedNodesKey] = treeList.GetSelectedNodes().Select(node => node.Key);
}
private void RestoreSelection() {
if (Session[selectedNodesKey] == null)
return;
var rowKeys = (IEnumerable<string>)Session[selectedNodesKey];
var iterator = treeList.CreateNodeIterator();
iterator.Reset();
while (iterator.Current != null) {
iterator.Current.Selected = rowKeys.Contains(iterator.Current.Key);
iterator.GetNext();
}
}
See Also