TreeNode.SelectAction プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As TreeNode Dim value As TreeNodeSelectAction value = instance.SelectAction instance.SelectAction = value
public: property TreeNodeSelectAction SelectAction { TreeNodeSelectAction get (); void set (TreeNodeSelectAction value); }
/** @property */ public TreeNodeSelectAction get_SelectAction () /** @property */ public void set_SelectAction (TreeNodeSelectAction value)
public function get SelectAction () : TreeNodeSelectAction public function set SelectAction (value : TreeNodeSelectAction)
TreeNodeSelectAction 値の 1 つ。既定値は TreeNodeSelectAction.Select です。

TreeView コントロールのノードのテキストは、2 種類のモード (選択モードとナビゲーション モード) のどちらかで表示できます。既定では、ノードは選択モードになっています。ノードをナビゲーション モードにするには、ノードの NavigateUrl プロパティを空の文字列 ("") 以外の値に設定します。ノードを選択モードにするには、ノードの NavigateUrl プロパティを空の文字列に設定します。
![]() |
---|
ノードがナビゲーション モードの場合、選択項目のイベントは、そのノードに対して無効になります。ノードをクリックすると、ページがサーバーにポストバックされてイベントが発生するのではなく、指定した URL にユーザーが移動します。 |
ノードが選択モードの場合、SelectAction プロパティを使用して、ノードの選択時に発生させる 1 つ以上のイベントを指定します。利用可能なオプションの一覧を次の表に示します。
TreeNodeSelectAction.Expand | ノードを展開した状態または折りたたんだ状態に切り替えます。TreeNodeExpanded イベントまたは TreeNodeCollapsed イベントを適宜発生させます。 |
TreeNodeSelectAction.None | |
TreeNodeSelectAction.Select | |
TreeNodeSelectAction.SelectExpand | ノードの選択時に SelectedNodeChanged イベントと TreeNodeExpanded イベントの両方を発生させます。ノードを展開することはできますが、折りたたむことはできません。 |
Topic | Location |
---|---|
方法 : TreeView のノード要素を追加または削除する (Visual Studio) | Visual Studio での ASP .NET Web アプリケーションの作成 |

SelectAction プロパティを使用して、ノードがクリックされたときに発生させるイベントを指定する方法を次のコード例に示します。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs) ' Call the appropriate method to populate a node at a particular level. Select Case e.Node.Depth Case 0 ' Populate the first-level nodes. PopulateCategories(e.Node) Case 1 ' Populate the second-level nodes. PopulateProducts(e.Node) Case Else ' Do nothing. End Select End Sub Sub PopulateCategories(ByVal node As TreeNode) ' Query for the product categories. These are the values ' for the second-level nodes. Dim ResultSet As DataSet = RunQuery("Select CategoryID, CategoryName From Categories") ' Create the second-level nodes. If ResultSet.Tables.Count > 0 Then ' Iterate through and create a new node for each row in the query results. ' Notice that the query results are stored in the table of the DataSet. Dim row As DataRow For Each row In ResultSet.Tables(0).Rows ' Create the new node. Notice that the CategoryId is stored in the Value property ' of the node. This will make querying for items in a specific category easier when ' the third-level nodes are created. Dim newNode As TreeNode = New TreeNode() Newnode.Text = row("CategoryName").ToString() Newnode.Value = row("CategoryID").ToString() ' Set the PopulateOnDemand property to true so that the child nodes can be ' dynamically populated. newNode.PopulateOnDemand = True ' Set additional properties for the node. newNode.SelectAction = TreeNodeSelectAction.Expand ' Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(newNode) Next End If End Sub Sub PopulateProducts(ByVal node As TreeNode) ' Query for the products of the current category. These are the values ' for the third-level nodes. Dim ResultSet As DataSet = RunQuery("Select ProductName From Products Where CategoryID=" & node.Value) ' Create the third-level nodes. If ResultSet.Tables.Count > 0 Then ' Iterate through and create a new node for each row in the query results. ' Notice that the query results are stored in the table of the DataSet. Dim row As DataRow For Each row In ResultSet.Tables(0).Rows ' Create the new node. Dim NewNode As TreeNode = New TreeNode(row("ProductName").ToString()) ' Set the PopulateOnDemand property to false, because these are leaf nodes and ' do not need to be populated. NewNode.PopulateOnDemand = False ' Set additional properties for the node. NewNode.SelectAction = TreeNodeSelectAction.None ' Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(NewNode) Next End If End Sub Function RunQuery(ByVal QueryString As String) As DataSet ' Declare the connection string. This example uses Microsoft SQL Server ' and connects to the Northwind sample database. Dim ConnectionString As String = "server=localhost;database=NorthWind;Integrated Security=SSPI" Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString) Dim DBAdapter As SqlDataAdapter Dim ResultsDataSet As DataSet = New DataSet Try ' Run the query and create a DataSet. DBAdapter = New SqlDataAdapter(QueryString, DBConnection) DBAdapter.Fill(ResultsDataSet) ' Close the database connection. DBConnection.Close() Catch ex As Exception ' Close the database connection if it is still open. If DBConnection.State = ConnectionState.Open Then DBConnection.Close() End If Message.Text = "Unable to connect to the database." End Try Return ResultsDataSet End Function </script> <html> <body> <form runat="server"> <h3>TreeView PopulateNodesFromClient Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" EnableClientScript="true" PopulateNodesFromClient="true" OnTreeNodePopulate="PopulateNode" runat="server"> <Nodes> <asp:TreeNode Text="Inventory" SelectAction="Expand" PopulateOnDemand="true"/> </Nodes> </asp:TreeView> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> void PopulateNode(Object sender, TreeNodeEventArgs e) { // Call the appropriate method to populate a node at a particular level. switch(e.Node.Depth) { case 0: // Populate the first-level nodes. PopulateCategories(e.Node); break; case 1: // Populate the second-level nodes. PopulateProducts(e.Node); break; default: // Do nothing. break; } } void PopulateCategories(TreeNode node) { // Query for the product categories. These are the values // for the second-level nodes. DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories"); // Create the second-level nodes. if(ResultSet.Tables.Count > 0) { // Iterate through and create a new node for each row in the query results. // Notice that the query results are stored in the table of the DataSet. foreach (DataRow row in ResultSet.Tables[0].Rows) { // Create the new node. Notice that the CategoryId is stored in the Value property // of the node. This will make querying for items in a specific category easier when // the third-level nodes are created. TreeNode newNode = new TreeNode(); newNode.Text = row["CategoryName"].ToString(); newNode.Value = row["CategoryID"].ToString(); // Set the PopulateOnDemand property to true so that the child nodes can be // dynamically populated. newNode.PopulateOnDemand = true; // Set additional properties for the node. newNode.SelectAction = TreeNodeSelectAction.Expand; // Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(newNode); } } } void PopulateProducts(TreeNode node) { // Query for the products of the current category. These are the values // for the third-level nodes. DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value); // Create the third-level nodes. if(ResultSet.Tables.Count > 0) { // Iterate through and create a new node for each row in the query results. // Notice that the query results are stored in the table of the DataSet. foreach (DataRow row in ResultSet.Tables[0].Rows) { // Create the new node. TreeNode NewNode = new TreeNode(row["ProductName"].ToString()); // Set the PopulateOnDemand property to false, because these are leaf nodes and // do not need to be populated. NewNode.PopulateOnDemand = false; // Set additional properties for the node. NewNode.SelectAction = TreeNodeSelectAction.None; // Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(NewNode); } } } DataSet RunQuery(String QueryString) { // Declare the connection string. This example uses Microsoft SQL Server // and connects to the Northwind sample database. String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI"; SqlConnection DBConnection = new SqlConnection(ConnectionString); SqlDataAdapter DBAdapter; DataSet ResultsDataSet = new DataSet(); try { // Run the query and create a DataSet. DBAdapter = new SqlDataAdapter(QueryString, DBConnection); DBAdapter.Fill(ResultsDataSet); // Close the database connection. DBConnection.Close(); } catch(Exception ex) { // Close the database connection if it is still open. if(DBConnection.State == ConnectionState.Open) { DBConnection.Close(); } Message.Text = "Unable to connect to the database."; } return ResultsDataSet; } </script> <html> <body> <form runat="server"> <h3>TreeView PopulateNodesFromClient Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" EnableClientScript="true" PopulateNodesFromClient="true" OnTreeNodePopulate="PopulateNode" runat="server"> <Nodes> <asp:TreeNode Text="Inventory" SelectAction="Expand" PopulateOnDemand="true"/> </Nodes> </asp:TreeView> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNodeSelectAction 列挙体
アセンブリ: System.Web (system.web.dll 内)

Public Enumeration TreeNodeSelectAction

メンバ名 | 説明 | |
---|---|---|
Expand | ノードの選択時に TreeNodeExpanded イベントを発生させます。 | |
None | ノードの選択時にイベントは発生しません。 | |
Select | ノードの選択時に SelectedNodeChanged イベントを発生させます。 | |
SelectExpand | ノードの選択時に SelectedNodeChanged イベントと TreeNodeExpanded イベントの両方を発生させます。 |

TreeNode コントロールの NavigateUrl プロパティに空の文字列 ("") 以外の値を設定した場合、ノードがクリックされると、指定した URL に移動します。NavigateUrl プロパティに空の文字列を設定した場合、ノードがクリックされると、ポストバックが発生します。SelectAction プロパティは、ポストバックで発生させるイベントを決定します。既定では、Select イベントが発生します。NavigateUrl プロパティが設定されている場合、イベントは発生しません。
![]() |
---|
SelectAction プロパティが None 値に設定されているノードでは、HoverNodeStyle プロパティは表示されません。 |

次のコード例では、TreeNodeSelectAction 列挙値を使用して、TreeView コントロール内のノードがクリックされたときに発生させるイベントを表す方法を示します。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> Sub PopulateNode(ByVal sender As Object, ByVal e As TreeNodeEventArgs) ' Call the appropriate method to populate a node at a particular level. Select Case e.Node.Depth Case 0 ' Populate the first-level nodes. PopulateCategories(e.Node) Case 1 ' Populate the second-level nodes. PopulateProducts(e.Node) Case Else ' Do nothing. End Select End Sub Sub PopulateCategories(ByVal node As TreeNode) ' Query for the product categories. These are the values ' for the second-level nodes. Dim ResultSet As DataSet = RunQuery("Select CategoryID, CategoryName From Categories") ' Create the second-level nodes. If ResultSet.Tables.Count > 0 Then ' Iterate through and create a new node for each row in the query results. ' Notice that the query results are stored in the table of the DataSet. Dim row As DataRow For Each row In ResultSet.Tables(0).Rows ' Create the new node. Notice that the CategoryId is stored in the Value property ' of the node. This will make querying for items in a specific category easier when ' the third-level nodes are created. Dim newNode As TreeNode = New TreeNode() Newnode.Text = row("CategoryName").ToString() Newnode.Value = row("CategoryID").ToString() ' Set the PopulateOnDemand property to true so that the child nodes can be ' dynamically populated. newNode.PopulateOnDemand = True ' Set additional properties for the node. newNode.SelectAction = TreeNodeSelectAction.Expand ' Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(newNode) Next End If End Sub Sub PopulateProducts(ByVal node As TreeNode) ' Query for the products of the current category. These are the values ' for the third-level nodes. Dim ResultSet As DataSet = RunQuery("Select ProductName From Products Where CategoryID=" & node.Value) ' Create the third-level nodes. If ResultSet.Tables.Count > 0 Then ' Iterate through and create a new node for each row in the query results. ' Notice that the query results are stored in the table of the DataSet. Dim row As DataRow For Each row In ResultSet.Tables(0).Rows ' Create the new node. Dim NewNode As TreeNode = New TreeNode(row("ProductName").ToString()) ' Set the PopulateOnDemand property to false, because these are leaf nodes and ' do not need to be populated. NewNode.PopulateOnDemand = False ' Set additional properties for the node. NewNode.SelectAction = TreeNodeSelectAction.None ' Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(NewNode) Next End If End Sub Function RunQuery(ByVal QueryString As String) As DataSet ' Declare the connection string. This example uses Microsoft SQL Server ' and connects to the Northwind sample database. Dim ConnectionString As String = "server=localhost;database=NorthWind;Integrated Security=SSPI" Dim DBConnection As SqlConnection = New SqlConnection(ConnectionString) Dim DBAdapter As SqlDataAdapter Dim ResultsDataSet As DataSet = New DataSet Try ' Run the query and create a DataSet. DBAdapter = New SqlDataAdapter(QueryString, DBConnection) DBAdapter.Fill(ResultsDataSet) ' Close the database connection. DBConnection.Close() Catch ex As Exception ' Close the database connection if it is still open. If DBConnection.State = ConnectionState.Open Then DBConnection.Close() End If Message.Text = "Unable to connect to the database." End Try Return ResultsDataSet End Function </script> <html> <body> <form runat="server"> <h3>TreeView PopulateNodesFromClient Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" EnableClientScript="true" PopulateNodesFromClient="true" OnTreeNodePopulate="PopulateNode" runat="server"> <Nodes> <asp:TreeNode Text="Inventory" SelectAction="Expand" PopulateOnDemand="true"/> </Nodes> </asp:TreeView> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <script runat="server"> void PopulateNode(Object sender, TreeNodeEventArgs e) { // Call the appropriate method to populate a node at a particular level. switch(e.Node.Depth) { case 0: // Populate the first-level nodes. PopulateCategories(e.Node); break; case 1: // Populate the second-level nodes. PopulateProducts(e.Node); break; default: // Do nothing. break; } } void PopulateCategories(TreeNode node) { // Query for the product categories. These are the values // for the second-level nodes. DataSet ResultSet = RunQuery("Select CategoryID, CategoryName From Categories"); // Create the second-level nodes. if(ResultSet.Tables.Count > 0) { // Iterate through and create a new node for each row in the query results. // Notice that the query results are stored in the table of the DataSet. foreach (DataRow row in ResultSet.Tables[0].Rows) { // Create the new node. Notice that the CategoryId is stored in the Value property // of the node. This will make querying for items in a specific category easier when // the third-level nodes are created. TreeNode newNode = new TreeNode(); newNode.Text = row["CategoryName"].ToString(); newNode.Value = row["CategoryID"].ToString(); // Set the PopulateOnDemand property to true so that the child nodes can be // dynamically populated. newNode.PopulateOnDemand = true; // Set additional properties for the node. newNode.SelectAction = TreeNodeSelectAction.Expand; // Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(newNode); } } } void PopulateProducts(TreeNode node) { // Query for the products of the current category. These are the values // for the third-level nodes. DataSet ResultSet = RunQuery("Select ProductName From Products Where CategoryID=" + node.Value); // Create the third-level nodes. if(ResultSet.Tables.Count > 0) { // Iterate through and create a new node for each row in the query results. // Notice that the query results are stored in the table of the DataSet. foreach (DataRow row in ResultSet.Tables[0].Rows) { // Create the new node. TreeNode NewNode = new TreeNode(row["ProductName"].ToString()); // Set the PopulateOnDemand property to false, because these are leaf nodes and // do not need to be populated. NewNode.PopulateOnDemand = false; // Set additional properties for the node. NewNode.SelectAction = TreeNodeSelectAction.None; // Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(NewNode); } } } DataSet RunQuery(String QueryString) { // Declare the connection string. This example uses Microsoft SQL Server // and connects to the Northwind sample database. String ConnectionString = "server=localhost;database=NorthWind;Integrated Security=SSPI"; SqlConnection DBConnection = new SqlConnection(ConnectionString); SqlDataAdapter DBAdapter; DataSet ResultsDataSet = new DataSet(); try { // Run the query and create a DataSet. DBAdapter = new SqlDataAdapter(QueryString, DBConnection); DBAdapter.Fill(ResultsDataSet); // Close the database connection. DBConnection.Close(); } catch(Exception ex) { // Close the database connection if it is still open. if(DBConnection.State == ConnectionState.Open) { DBConnection.Close(); } Message.Text = "Unable to connect to the database."; } return ResultsDataSet; } </script> <html> <body> <form runat="server"> <h3>TreeView PopulateNodesFromClient Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" EnableClientScript="true" PopulateNodesFromClient="true" OnTreeNodePopulate="PopulateNode" runat="server"> <Nodes> <asp:TreeNode Text="Inventory" SelectAction="Expand" PopulateOnDemand="true"/> </Nodes> </asp:TreeView> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTreeNode.SelectActionを検索する場合は、下記のリンクをクリックしてください。

- TreeNode.SelectActionのページへのリンク