TreeViewEventArgs.Action TreeViewEventArgs.Action TreeViewEventArgs.Action TreeViewEventArgs.Action Property

定義

イベントを発生させたアクションの種類を取得します。Gets the type of action that raised the event.

public:
 property System::Windows::Forms::TreeViewAction Action { System::Windows::Forms::TreeViewAction get(); };
public System.Windows.Forms.TreeViewAction Action { get; }
member this.Action : System.Windows.Forms.TreeViewAction
Public ReadOnly Property Action As TreeViewAction

プロパティ値

イベントを発生させた TreeViewAction の種類。The type of TreeViewAction that raised the event.

次の例を示しています、カスタマイズされたTreeViewします。The following example illustrates a customized TreeView. 継承することによって、TreeViewクラスでは、このカスタムのバージョンが、通常の機能をすべてTreeViewします。By inheriting the TreeView class, this custom version has all the functionality of a normal TreeView. コンス トラクターでさまざまなプロパティ値を変更するには、独自の外観が提供します。Changing various property values in the constructor provides a unique appearance. ShowPlusMinusプロパティが false に設定、カスタマイズされたコントロールもオーバーライド、OnAfterSelectメソッド ノードを展開し、クリックしてされたときに折りたたまれているようにします。Because the ShowPlusMinus property is set to false, the customized control also overrides the OnAfterSelect method so nodes can be expanded and collapsed when they are clicked.

この方法でカスタマイズされたコントロールは、個々 のプロジェクトで指定するコントロールのプロパティを必要とせず、一貫性のあるインターフェイスを提供しやすく、組織全体で使用できます。A control that is customized in this way can be used throughout an organization, making it easy to provide a consistent interface without requiring the control properties to be specified in each individual project.

public ref class CustomizedTreeView: public TreeView
{
public:
   CustomizedTreeView()
   {

      // Customize the TreeView control by setting various properties.
      BackColor = System::Drawing::Color::CadetBlue;
      FullRowSelect = true;
      HotTracking = true;
      Indent = 34;
      ShowPlusMinus = false;

      // The ShowLines property must be false for the FullRowSelect
      // property to work.
      ShowLines = false;
   }

protected:
   virtual void OnAfterSelect( TreeViewEventArgs^ e ) override
   {
      // Confirm that the user initiated the selection.
      // This prevents the first node from expanding when it is
      // automatically selected during the initialization of
      // the TreeView control.
      if ( e->Action != TreeViewAction::Unknown )
      {
         if ( e->Node->IsExpanded )
         {
            e->Node->Collapse();
         }
         else
         {
            e->Node->Expand();
         }
      }

      
      // Remove the selection. This allows the same node to be
      // clicked twice in succession to toggle the expansion state.
      SelectedNode = nullptr;
   }
};
public class CustomizedTreeView : TreeView
{
    public CustomizedTreeView()
    {
        // Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue;
        FullRowSelect = true;
        HotTracking = true;
        Indent = 34;
        ShowPlusMinus = false;

        // The ShowLines property must be false for the FullRowSelect 
        // property to work.
        ShowLines = false;
    }

    protected override void OnAfterSelect(TreeViewEventArgs e)
    {
        // Confirm that the user initiated the selection.
        // This prevents the first node from expanding when it is
        // automatically selected during the initialization of 
        // the TreeView control.
        if (e.Action != TreeViewAction.Unknown)
        {
            if (e.Node.IsExpanded) 
            {
                e.Node.Collapse();
            }
            else 
            {
                e.Node.Expand();
            }
        }

        // Remove the selection. This allows the same node to be
        // clicked twice in succession to toggle the expansion state.
        SelectedNode = null;
    }

}
Public Class CustomizedTreeView
    Inherits TreeView

    Public Sub New()
        ' Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue
        FullRowSelect = True
        HotTracking = True
        Indent = 34
        ShowPlusMinus = False

        ' The ShowLines property must be false for the FullRowSelect 
        ' property to work.
        ShowLines = False
    End Sub 'New


    Protected Overrides Sub OnAfterSelect(ByVal e As TreeViewEventArgs)
        ' Confirm that the user initiated the selection.
        ' This prevents the first node from expanding when it is
        ' automatically selected during the initialization of 
        ' the TreeView control.
        If e.Action <> TreeViewAction.Unknown Then
            If e.Node.IsExpanded Then
                e.Node.Collapse()
            Else
                e.Node.Expand()
            End If
        End If

        ' Remove the selection. This allows the same node to be
        ' clicked twice in succession to toggle the expansion state.
        SelectedNode = Nothing
    End Sub 'OnAfterSelect

End Class 'CustomizedTreeView 

適用対象

こちらもご覧ください