Bewerken

Delen via


TreeNodeBinding.ShowCheckBox Property

Definition

Gets or sets a value indicating whether a check box is displayed next to a node to which the TreeNodeBinding object is applied.

public:
 property Nullable<bool> ShowCheckBox { Nullable<bool> get(); void set(Nullable<bool> value); };
public bool? ShowCheckBox { get; set; }
member this.ShowCheckBox : Nullable<bool> with get, set
Public Property ShowCheckBox As Nullable(Of Boolean)

Property Value

true to display a check box next to a node to which the TreeNodeBinding object is applied; otherwise, false. The default is false.

Examples

This section contains two code examples. The first code example demonstrates how to use the ShowCheckBox property to specify whether a check box is displayed for a node. The second code example provides sample XML data for the first code example.

The following example demonstrates how to use the ShowCheckBox property to specify whether a check box is displayed for a node. For this example to work correctly, you must copy the sample XML data, provided after this code example, to a file named Book.xml.


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void BookTreeView_CheckChanged(Object sender, TreeNodeEventArgs e)
  {
   
    // Display the nodes that have their check box selected.
    Message.Text = "You selected the following check boxes: ";
   
    foreach(TreeNode node in BookTreeView.CheckedNodes)
    {
    
      Message.Text += node.Text + " ";
    
    }
    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBinding ShowCheckBox Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBinding ShowCheckBox Example</h3>
    
      <asp:treeview id="BookTreeView" 
         datasourceid="BookXmlDataSource"
         expanddepth="2"
         OnTreeNodeCheckChanged="BookTreeView_CheckChanged"   
         runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"
            ShowCheckBox="True"/>
        </DataBindings>
         
      </asp:treeview>
      
      <asp:xmldatasource id="BookXmlDataSource"  
         datafile="Book.xml"
         runat="server">
      </asp:xmldatasource>
      
      <br/><br/>
      
      <asp:label id="Message"
        runat="server"/>
      
      <hr/>
      
      <asp:button id="SubmitButton"
        Text="Submit"
        runat="server"/>
    
    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub BookTreeView_CheckChanged(sender As Object, e As TreeNodeEventArgs)
   
    ' Display the nodes that have their check box selected.
    Message.Text = "You selected the following check boxes: "
   
    Dim node As TreeNode
    
    For Each node in BookTreeView.CheckedNodes
    
      Message.Text &= node.Text & " "
    
    Next
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBinding ShowCheckBox Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBinding ShowCheckBox Example</h3>
    
      <asp:treeview id="BookTreeView" 
         datasourceid="BookXmlDataSource"
         expanddepth="2"
         OnTreeNodeCheckChanged="BookTreeView_CheckChanged"   
         runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"
            ShowCheckBox="True"/>
        </DataBindings>
         
      </asp:treeview>
      
      <asp:xmldatasource id="BookXmlDataSource"  
         datafile="Book.xml"
         runat="server">
      </asp:xmldatasource>
      
      <br/><br/>
      
      <asp:label id="Message"
        runat="server"/>
      
      <hr/>
      
      <asp:button id="SubmitButton"
        text="Submit"
        runat="server"/>
    
    </form>
  </body>
</html>

The following code example provides sample XML data for the preceding code example.

<Book Title="Book Title">  
    <Chapter Heading="Chapter 1">  
        <Section Heading="Section 1">  
        </Section>  
        <Section Heading="Section 2">  
        </Section>  
    </Chapter>  
    <Chapter Heading="Chapter 2">  
        <Section Heading="Section 1">  
        </Section>  
    </Chapter>  
    <Appendix Heading="Appendix A">  
    </Appendix>  
</Book>  

Remarks

To provide multinode selection support in the TreeView control, you can display check boxes next to an image in the node. When the TreeView control is bound to a data source, use the ShowCheckBox property to specify the value to bind to the ShowCheckBox property of a TreeNode object. This binding relationship affects all TreeNode objects to which the TreeNodeBinding object is applied. The ShowCheckBox property is used to show or hide the check box for a node.

Note

Although the ShowCheckBox property can be used to display check boxes, it is more common to use the ShowCheckBoxes property of the TreeView control. However, the ShowCheckBoxes property affects every node type that is specified by the property; therefore, the ShowCheckBox property is often used to override that setting for a node to which the TreeNodeBinding object is applied. You can selectively override the ShowCheckBox property by setting the ShowCheckBox property of each node directly.

The value of this property is stored in view state.

Applies to

See also