Skip to main content

TreeListNode.IsExpandButtonVisible Property

Gets or sets whether the expand button is displayed within the node or not.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v23.2.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public DefaultBoolean IsExpandButtonVisible { get; set; }

Property Value

Type Description
DefaultBoolean

A DefaultBoolean enumeration value that specifies the expand button’s visibility within the node.

Available values:

Name Description Return Value
True

The value is true.

0

False

The value is false.

1

Default

The value is specified by a global option or a higher-level object.

2

Remarks

The TreeListView.NodeExpanding event can be handled to dynamically create child nodes. In this instance, when expanding a node, you do not know whether it has child nodes or not. If the node has no child nodes, hide the expand button by setting the IsExpandButtonVisible property to false.

To learn more, see Expanding and Collapsing Nodes .

Example

In this example, the TreeListView displays the file/folder tree. The TreeListView.NodeExpanding event allows you to create child nodes dynamically when a user expands a parent node.

View Example: Load Nodes Dynamically

<dxg:GridControl x:Name="grid">
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="Name"/>
        <dxg:GridColumn FieldName="ItemType"/>
        <dxg:GridColumn FieldName="Size">
            <dxg:GridColumn.EditSettings>
                <dxe:TextEditSettings HorizontalContentAlignment="Right"/>
            </dxg:GridColumn.EditSettings>
        </dxg:GridColumn>
        <dxg:GridColumn FieldName="FullName"/>
    </dxg:GridControl.Columns>
    <dxg:GridControl.View>
        <dxg:TreeListView x:Name="view" 
                          AllowEditing="False"
                          AutoWidth="True"
                          NodeExpanding="OnNodeExpanding"/>
    </dxg:GridControl.View>
</dxg:GridControl>
public partial class MainWindow : Window {
    FileSystemDataProvider Helper { get; set; }
    public MainWindow() {
        InitializeComponent();
        Helper = new FileSystemHelper();
        InitDrives();
    }
    public void InitDrives() {
        grid.BeginDataUpdate();
        try {
            string[] root = Helper.GetLogicalDrives();

            foreach (string s in root) {
                TreeListNode node = new TreeListNode() { Content = new FileSystemItem(s, "Drive", "<Drive>", s) };
                view.Nodes.Add(node);
                node.IsExpandButtonVisible = DefaultBoolean.True;
            }
        }
        catch { }
        grid.EndDataUpdate();
    }

    private void OnNodeExpanding(object sender, DevExpress.Xpf.Grid.TreeList.TreeListNodeAllowEventArgs e) {
        TreeListNode node = e.Node;
        if (node.Tag == null || (bool)node.Tag == false) {
            InitFolder(node);
            node.Tag = true;
        }
    }

    private void InitFolder(TreeListNode treeListNode) {
        grid.BeginDataUpdate();
        InitFolders(treeListNode);
        InitFiles(treeListNode);
        grid.EndDataUpdate();
    }

    private void InitFolders(TreeListNode treeListNode) {
        FileSystemItem item = treeListNode.Content as FileSystemItem;
        if (item == null) return;

        try {
            string[] root = Helper.GetDirectories(item.FullName);
            foreach (string s in root) {
                try {
                    TreeListNode node = new TreeListNode() { Content = new FileSystemItem(Helper.GetDirectoryName(s), "Folder", "<Folder>", s) };
                    treeListNode.Nodes.Add(node);

                    node.IsExpandButtonVisible = HasFiles(s) ? DefaultBoolean.True : DefaultBoolean.False;
                }
                catch { }
            }
        }
        catch { }
    }

    private void InitFiles(TreeListNode treeListNode) {
        FileSystemItem item = treeListNode.Content as FileSystemItem;
        if (item == null) return;
        TreeListNode node;
        try {
            string[] root = Helper.GetFiles(item.FullName);
            foreach (string s in root) {
                node = new TreeListNode() { Content = new FileSystemItem(Helper.GetFileName(s), "File", Helper.GetFileSize(s).ToString(), s) };
                node.IsExpandButtonVisible = DefaultBoolean.False;
                treeListNode.Nodes.Add(node);
            }
        }
        catch { }
    }

    private bool HasFiles(string path) {
        string[] root = Helper.GetFiles(path);
        if (root.Length > 0) return true;
        root = Helper.GetDirectories(path);
        if (root.Length > 0) return true;
        return false;
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the IsExpandButtonVisible property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also