TreeView.SelectedNodeとは? わかりやすく解説

TreeView.SelectedNode プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

TreeView コントロール選択されノードを表す TreeNode オブジェクト取得します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public ReadOnly Property
 SelectedNode As TreeNode
Dim instance As TreeView
Dim value As TreeNode

value = instance.SelectedNode
public TreeNode SelectedNode { get; }
public:
property TreeNode^ SelectedNode {
    TreeNode^ get ();
}
/** @property */
public TreeNode get_SelectedNode ()
public function get SelectedNode
 () : TreeNode

プロパティ
TreeView選択されノードを表す TreeNode

解説解説

TreeView コントロール内のノードテキストは、2 種類モード (選択モードナビゲーション モード) のどちらか表示できます既定では、ノード選択モードになってます。ノードナビゲーション モードにするには、ノードの NavigateUrl プロパティを、空の文字列 ("") 以外の値に設定しますノード選択モードにするには、ノードNavigateUrl プロパティ空の文字列 ("") に設定します

ノード選択モード場合ユーザーノード内のテキストクリックしてノード選択できますSelectedNode プロパティ使用してTreeView コントロール選択されているノード確認します

メモメモ

TreeView コントロールハイパーリンク表示されている場合ノード選択することはできません。ハイパーリンク表示されている場合SelectedNode プロパティは常に null 参照 (Visual Basic では Nothing) を返します

ユーザー新しノードテキストクリックしてTreeView コントロール内の別のノード選択すると、既定では SelectedNodeChanged イベント発生します。このプロパティの SelectAction プロパティ設定して別のイベント指定することもできます利用可能オプションの一覧を次の表に示します

選択アクション

説明

Expand

ノード展開した状態または折りたたんだ状態に切り替えます。TreeNodeExpanded イベントまたは TreeNodeCollapsed イベント適宜発生させます

None

ノード選択時にイベント発生しません。

Select

ノード選択時に SelectedNodeChanged イベント発生させます

SelectExpand

ノード選択時に SelectedNodeChanged イベントTreeNodeExpanded イベント両方発生させますノード展開することはできますが、折りたたむことはできません。

メモメモ

HoverNodeStyle は、SelectAction プロパティTreeNodeSelectAction.None設定されているノードでは表示されません。

使用例使用例

SelectedNode プロパティ使用してTreeView コントロール選択されノードの値を確認する方法次のコード例示します

<%@ Page Language="VB" %>

<script runat="server">

    Sub Select_Change(ByVal sender As
 Object, ByVal e As EventArgs)

        Message.Text = "You selected: " & LinksTreeView.SelectedNode.Text

    End Sub

</script>

<html>

    <body>
        <form runat="server">
        
            <h3>TreeView SelectedNodeStyle Example</h3>
            
            <asp:TreeView id="LinksTreeView"
                Font-Name= "Arial"
                ForeColor="Blue"
                SelectedNodeStyle-ForeColor="Green"
                SelectedNodeStyle-VerticalPadding="0"
                OnSelectedNodeChanged="Select_Change"
   
                runat="server">
                 
                <LevelStyles>
                
                    <asp:TreeNodeStyle ChildNodesPadding="10"
 
                        Font-Bold="true" 
                        Font-Size="12pt" 
                        ForeColor="DarkGreen"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5"
 
                        Font-Bold="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5"
 
                        Font-UnderLine="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="10"
 
                        Font-Size="8pt"/>
                         
                </LevelStyles>
                 
                <Nodes>
                
                    <asp:TreeNode Text="Table of Contents"
                        SelectAction="None">
                         
                        <asp:TreeNode Text="Chapter One">
                        
                            <asp:TreeNode Text="Section 1.0">
                            
                                <asp:TreeNode Text="Topic 1.0.1"/>
                                <asp:TreeNode Text="Topic 1.0.2"/>
                                <asp:TreeNode Text="Topic 1.0.3"/>
                            
                            </asp:TreeNode>
                            
                            <asp:TreeNode Text="Section 1.1">
                            
                                <asp:TreeNode Text="Topic 1.1.1"/>
                                <asp:TreeNode Text="Topic 1.1.2"/>
                                <asp:TreeNode Text="Topic 1.1.3"/>
                                <asp:TreeNode Text="Topic 1.1.4"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                        <asp:TreeNode Text="Chapter Two">
                        
                            <asp:TreeNode Text="Section 2.0">
                            
                                <asp:TreeNode Text="Topic 2.0.1"/>
                                <asp:TreeNode Text="Topic 2.0.2"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                    </asp:TreeNode>
                    <asp:TreeNode Text="Appendix A"
 />
                    <asp:TreeNode Text="Appendix B"
 />
                    <asp:TreeNode Text="Appendix C"
 />
                
                </Nodes>
                
            </asp:TreeView>
            
            <br><br>
            
            <asp:Label id="Message" runat="server"/>
            
        </form>
    </body>
</html>

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

<script runat="server">

    void Select_Change(Object sender, EventArgs e)
    {

        Message.Text = "You selected: " + LinksTreeView.SelectedNode.Text;

    }

</script>

<html>

    <body>
        <form runat="server">
        
            <h3>TreeView SelectedNodeStyle Example</h3>

            <asp:TreeView id="LinksTreeView"
                Font-Name= "Arial"
                ForeColor="Blue"
                SelectedNodeStyle-ForeColor="Green"
                SelectedNodeStyle-VerticalPadding="0"
                OnSelectedNodeChanged="Select_Change"   
                runat="server">
                 
                <LevelStyles>
                
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Bold="true" 
                        Font-Size="12pt" 
                        ForeColor="DarkGreen"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                        Font-Bold="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="5" 
                        Font-UnderLine="true" 
                        Font-Size="10pt"/>
                    <asp:TreeNodeStyle ChildNodesPadding="10" 
                        Font-Size="8pt"/>
                         
                </LevelStyles>
                 
                <Nodes>
                
                    <asp:TreeNode Text="Table of Contents"
                        SelectAction="None">
                         
                        <asp:TreeNode Text="Chapter One">
                        
                            <asp:TreeNode Text="Section 1.0">
                            
                                <asp:TreeNode Text="Topic 1.0.1"/>
                                <asp:TreeNode Text="Topic 1.0.2"/>
                                <asp:TreeNode Text="Topic 1.0.3"/>
                            
                            </asp:TreeNode>
                            
                            <asp:TreeNode Text="Section 1.1">
                            
                                <asp:TreeNode Text="Topic 1.1.1"/>
                                <asp:TreeNode Text="Topic 1.1.2"/>
                                <asp:TreeNode Text="Topic 1.1.3"/>
                                <asp:TreeNode Text="Topic 1.1.4"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                        <asp:TreeNode Text="Chapter Two">
                        
                            <asp:TreeNode Text="Section 2.0">
                            
                                <asp:TreeNode Text="Topic 2.0.1"/>
                                <asp:TreeNode Text="Topic 2.0.2"/>
                            
                            </asp:TreeNode>
                        
                        </asp:TreeNode>
                        
                    </asp:TreeNode>
                    <asp:TreeNode Text="Appendix A" />
                    <asp:TreeNode Text="Appendix B" />
                    <asp:TreeNode Text="Appendix C" />
                
                </Nodes>
                
            </asp:TreeView>
            
            <br><br>
            
            <asp:Label id="Message" runat="server"/>
            
        </form>
    </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeView クラス
TreeView メンバ
System.Web.UI.WebControls 名前空間
TreeNode クラス
ShowCheckBoxes
SelectedNodeChanged
TreeNodeExpanded
TreeNode.SelectAction プロパティ
TreeNodeBinding.SelectAction プロパティ

TreeView.SelectedNode プロパティ

ツリー ビュー コントロールで現在選択されているツリー ノード取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Property SelectedNode As
 TreeNode
Dim instance As TreeView
Dim value As TreeNode

value = instance.SelectedNode

instance.SelectedNode = value
public TreeNode SelectedNode { get; set;
 }
public:
property TreeNode^ SelectedNode {
    TreeNode^ get ();
    void set (TreeNode^ value);
}
/** @property */
public TreeNode get_SelectedNode ()

/** @property */
public void set_SelectedNode (TreeNode value)
public function get SelectedNode
 () : TreeNode

public function set SelectedNode
 (value : TreeNode)

プロパティ
ツリー ビュー コントロールで現在選択されている TreeNode。

解説解説
使用例使用例

TreeView の PathSeparator プロパティ設定しSelectedNode の TreeNodeCollection に含まれている子ツリー ノードの数を表示するコード例次に示しますツリー ビュー コントロール内のすべてのツリー ノード対する子ツリー ノード割合表示されます。この例は、Form 上に、ButtonTreeView コントロール配置され、その TreeView に、複数TreeNode オブジェクト (3 レベル以上を推奨) を持つ TreeNodeCollection設定されていることを前提にしています。

Private Sub myButton_Click(ByVal
 sender As Object, _
  ByVal e As System.EventArgs) Handles
 myButton.Click
   ' Set the tre view's PathSeparator property.
   myTreeView.PathSeparator = "."

   ' Get the count of the child tree nodes contained in the SelectedNode.
   Dim myNodeCount As Integer
 = myTreeView.SelectedNode.GetNodeCount(True)
   Dim myChildPercentage As Decimal
 = CDec(myNodeCount) / _
      CDec(myTreeView.GetNodeCount(True)) * 100

   ' Display the tree node path and the number of child nodes it and
 the tree view have.
   MessageBox.Show(("The '" + myTreeView.SelectedNode.FullPath
 + "' node has " _
      + myNodeCount.ToString() + " child nodes." +
 Microsoft.VisualBasic.ControlChars.Lf _
      + "That is " + String.Format("{0:###.##}",
 myChildPercentage) _
      + "% of the total tree nodes in the tree view control."))
End Sub
private void myButton_Click(object sender,
 System.EventArgs e)
{
   // Set the tre view's PathSeparator property.
   myTreeView.PathSeparator = ".";

   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView.SelectedNode.GetNodeCount(true);
   decimal myChildPercentage = ((decimal)myNodeCount/
     (decimal)myTreeView.GetNodeCount(true)) * 100;

   // Display the tree node path and the number of child nodes it and
 the tree view have.
   MessageBox.Show("The '" + myTreeView.SelectedNode.FullPath + "'
 node has " 
     + myNodeCount.ToString() + " child nodes.\nThat is " 
     + string.Format("{0:###.##}", myChildPercentage)
 
     + "% of the total tree nodes in the tree view control.");
}
void myButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/
 )
{
   
   // Set the tre view's PathSeparator property.
   myTreeView->PathSeparator = ".";
   
   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView->SelectedNode->GetNodeCount(
 true );
   Decimal myChildPercentage = ((Decimal)myNodeCount / (Decimal)myTreeView->GetNodeCount(
 true )) * 100;
   
   // Display the tree node path and the number of child nodes it and
 the tree view have.
   MessageBox::Show( String::Concat( "The '", myTreeView->SelectedNode->FullPath,
 "' node has ", myNodeCount, " child nodes.\nThat is ", String::Format(
 "{0:###.##}", myChildPercentage ), "% of the total tree nodes in the tree view control." ) );
}
private void myButton_Click(Object sender,
 System.EventArgs e)
{
    // Set the tre view's PathSeparator property.
    myTreeView.set_PathSeparator(".");
    // Get the count of the child tree nodes contained in the SelectedNode.
    int myNodeCount = myTreeView.get_SelectedNode().GetNodeCount(true);
    System.Decimal myChildPercentage =
        Decimal.Multiply(Decimal.Divide(new Decimal(myNodeCount)
,
        new Decimal(myTreeView.GetNodeCount(true))),
 new Decimal(100));
    // Display the tree node path and the number of child nodes it and
 the
    // tree view have.
    MessageBox.Show("The '" + myTreeView.get_SelectedNode().get_FullPath()
        + "' node has " + ((Int32)myNodeCount).ToString()
        + " child nodes.\nThat is " + String.Format("{0:###.##}"
,
        myChildPercentage)
        + "% of the total tree nodes in the tree view control.");
} //myButton_Click
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTreeView.SelectedNodeを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTreeView.SelectedNodeを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTreeView.SelectedNode を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TreeView.SelectedNode」の関連用語

TreeView.SelectedNodeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeView.SelectedNodeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS