TreeNode.ValuePath プロパティ

定義

ルート ノードから現在のノードまでのパスを取得します。

public:
 property System::String ^ ValuePath { System::String ^ get(); };
[System.ComponentModel.Browsable(false)]
public string ValuePath { get; }
[<System.ComponentModel.Browsable(false)>]
member this.ValuePath : string
Public ReadOnly Property ValuePath As String

プロパティ値

ルート ノードから現在のノードまでのパスを構成するノードの値のコンマ区切りのリスト。

属性

次のコード例では、 プロパティを解析する方法を ValuePath 示します。


<%@ 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 Index_Changed(Object sender, EventArgs e)
  {

    // Set the PathSeparator character based on the user's selection.
    // Notice that the value must be converted to a Char data type.
    BookTreeView.PathSeparator = Convert.ToChar(List.SelectedItem.Text);

    // Display the ValuePath values for the second-level nodes.
    Message.Text = "The ValuePath values for the second-level nodes are:<br />";
    foreach(TreeNode node in BookTreeView.Nodes[0].ChildNodes)
    {

      // Create the delimiter array with the PathSeparator value for the Split method.
      Char[] DelimiterArray = new Char[1];
      DelimiterArray[0] = BookTreeView.PathSeparator;

      // Parse the ValuePath value using the delimiter array.
      String[] NodeValues = node.ValuePath.Split(DelimiterArray);

      // Display the node values.
      for(int i=0; i<NodeValues.Length; i++)
      {
        if(i != NodeValues.Length - 1)
        {   
          // Append the delimiter character.
          Message.Text += NodeValues[i] + BookTreeView.PathSeparator.ToString();
        }
        else
        {
          // Do not append the delimiter character.
          Message.Text += NodeValues[i];
        }

      }

      // Append a line break for the next node.
      Message.Text += "<br />";

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>TreeView PathSeparator Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PathSeparator Example</h3>
      
      <asp:TreeView id="BookTreeView"
        ExpandDepth="-1"
        PathSeparator="/"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Chapter 1" 
            Text="Chapter 1">
             
            <asp:TreeNode Value="Section 1"
              Text="Section 1">
               
              <asp:TreeNode Value="Paragraph 1" 
                Text="Paragraph 1">
              </asp:TreeNode>
                
            </asp:TreeNode>
            
            <asp:TreeNode Value="Section 2" 
              Text="Section 2">
            </asp:TreeNode>
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br />
      
      <asp:Label id="Message" runat="server"/>
      
      <hr />
      
      Select a path separator value:<br />
      
      <asp:DropDownList ID="List"
        AutoPostBack="true"
        OnSelectedIndexChanged="Index_Changed"   
        runat="server">
      
        <asp:ListItem Selected="true">/</asp:ListItem>
        <asp:ListItem>\</asp:ListItem>
        <asp:ListItem>|</asp:ListItem>
        <asp:ListItem>,</asp:ListItem>
        <asp:ListItem>;</asp:ListItem>
      
      </asp:DropDownList>

    </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 Index_Changed(ByVal sender As Object, ByVal e As EventArgs)

    ' Set the PathSeparator character based on the user's selection.
    ' Notice that the value must be converted to a Char data type.
    BookTreeView.PathSeparator = Convert.ToChar(List.SelectedItem.Text)

    ' Display the ValuePath values for the second-level nodes.
    Message.Text = "The ValuePath values for the second-level nodes are:<br />"
    Dim node As TreeNode
    For Each node In BookTreeView.Nodes(0).ChildNodes

      ' Create the delimiter array with the PathSeparator value for the Split method.
      Dim DelimiterArray(1) As Char
      DelimiterArray(0) = BookTreeView.PathSeparator

      ' Parse the ValuePath value using the delimiter array.
      Dim NodeValues() As String = node.ValuePath.Split(DelimiterArray)

      ' Display the node values.
      Dim i As Integer

      For i = 0 To NodeValues.Length - 1

        If i <> NodeValues.Length - 1 Then

          ' Append the delimiter character.
          Message.Text &= NodeValues(i) & BookTreeView.PathSeparator.ToString()

        Else

          ' Do not append the delimiter character.
          Message.Text &= NodeValues(i)

        End If

      Next

      ' Append a line break for the next node.
      Message.Text &= "<br />"

    Next

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >

  <head runat="server">
    <title>TreeView PathSeparator Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeView PathSeparator Example</h3>
      
      <asp:TreeView id="BookTreeView"
        ExpandDepth="-1"
        PathSeparator="/"
        runat="server">
         
        <Nodes>
        
          <asp:TreeNode Value="Chapter 1" 
            Text="Chapter 1">
             
            <asp:TreeNode Value="Section 1"
              Text="Section 1">
               
              <asp:TreeNode Value="Paragraph 1" 
                Text="Paragraph 1">
              </asp:TreeNode>
                
            </asp:TreeNode>
            
            <asp:TreeNode Value="Section 2" 
              Text="Section 2">
            </asp:TreeNode>
            
          </asp:TreeNode>
        
        </Nodes>
        
      </asp:TreeView>
      
      <br />
      
      <asp:Label id="Message" runat="server"/>
      
      <hr />
      
      Select a path separator value:<br />
      
      <asp:DropDownList ID="List"
        AutoPostBack="true"
        OnSelectedIndexChanged="Index_Changed"   
        runat="server">
      
        <asp:ListItem Selected="true">/</asp:ListItem>
        <asp:ListItem>\</asp:ListItem>
        <asp:ListItem>|</asp:ListItem>
        <asp:ListItem>,</asp:ListItem>
        <asp:ListItem>;</asp:ListItem>
      
      </asp:DropDownList>

    </form>
  </body>
</html>

注釈

ValuePathプロパティには、ルート ノードから現在のノードへのパスを形成するノード値の区切り記号で区切られたリストが含まれています。 プロパティを PathSeparator 使用して、ノード値を区切るために使用する区切り文字を指定します。 この値は、個々の値のリストを解析するとき、またはクラスの メソッドに引数として渡す場合に一般的にFindNodeTreeView使用されます。

コントロールに表示される TreeView 値によっては、競合を防ぐために区切り文字を変更する必要がある場合があります。 たとえば、区切り文字をコンマに設定した場合、表示される値にはコンマを含めないようにしてください。それ以外の場合は、 プロパティを ValuePath 正確に解析できません。

注意

同じレベルのノードは、それぞれ プロパティTreeViewに対して一意の値をValue持つ必要があります。コントロールは、同じ値を持つ同じレベルの異なるノードを区別できません。 このシナリオでは、ユーザーが重複する値を持つノードをクリックすると、コントロールの最初に TreeView 表示されるノードが選択されます。

適用対象

こちらもご覧ください