private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e) { if (e.Node.Nodes.Count > 0) { e.Cancel = true; // Cancel the event } }
private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Node.Nodes.Count == 0) { e.Cancel = true; // Cancel the event } }Package library: System.Windows.Forms.